LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 10-15-2007, 08:26 AM   #1
linux_1
LQ Newbie
 
Registered: Aug 2007
Posts: 12

Rep: Reputation: 0
how to pass the parameter to command sed


Hello everyone.

Here I want to ask for help on "how to pass parameters to command sed"

background:
I am trying to do exercise under Csh

purpose:
just output the even line from one file.

current script:
#!/bin/csh

set Tn=`wc -l < file1`

set i = 2

while ($i <= $Tn)
sed '$i d' file1
@ i = $i + 2
end


The content of file1 is:
1
2
3
4
5
6
7
8
9
10

The problem here is that the output is always not what I want to get.
It is always as below
1
2
3
4
5
6
7
8
9
d
10


Not
2
4
6
8
10

Can you give a hand?

thank you.

Last edited by linux_1; 10-15-2007 at 08:28 AM.
 
Old 10-15-2007, 10:31 AM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
Answering exactly what you asked: Use double quotes instead....
Code:
sed "$i d" file1
Using single quotes, the sed receives the string '$i', not the expansion of $i which is 2,4,6...
Double quotes allow that expansion.

...but this will not solve your homework. try your script now and you will see the result.
 
Old 10-15-2007, 02:00 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
My favorite tutorial on SED:

http://www.grymoire.com/Unix/Sed.html
 
Old 10-15-2007, 07:10 PM   #4
linux_1
LQ Newbie
 
Registered: Aug 2007
Posts: 12

Original Poster
Rep: Reputation: 0
Thank you, marozsas and, Thank you, pixellany.

Your answers help me a lot. Have a nice day.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
gtk - How to pass in a parameter Ian D Programming 4 10-28-2005 11:23 AM
how do I pass a module parameter? maerong Debian 2 02-07-2005 07:33 AM
bash: pass a parameter to xview nimra Programming 2 06-28-2004 09:18 PM
PHP Pass Parameter Gerardoj Programming 2 05-25-2004 08:12 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 08:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration