Beginner in UNIX/Shell Script - Please help

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Beginner in UNIX/Shell Script - Please help

 
0
  #11
Dec 1st, 2008
Hey there,

Glad to help

You should be all right with that, just be sure to escape your shell special character when you echo:

echo "s/$word/$in/g" >> filename2

would end up echoing the value of your variables into your sed script.

echo "s/\$word/\$in/g" >> filename2

should take care of that

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 6
Reputation: learnpro is an unknown quantity at this point 
Solved Threads: 0
learnpro learnpro is offline Offline
Newbie Poster

Re: Beginner in UNIX/Shell Script - Please help

 
0
  #12
Dec 1st, 2008
Thanks again for replying. I would not have bothered you again, but the syntax seems to be missing something on my end.
sed -f "filename2" "originalfile"
Doing so does not apply the output of filename2 to the original file. Strangely, when I use sed without -n option, it displays the output correctly on stdout, however, same does not apply to the file when I takeoff -n. Any thing you may suggest to fix this !
Thanks and I appreciate all your help.
Last edited by learnpro; Dec 1st, 2008 at 12:57 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Beginner in UNIX/Shell Script - Please help

 
0
  #13
Dec 1st, 2008
Hey,

The important thing is that you're making forward progress!

For the -n flag, you're instructing sed not to print anything - which is good when you don't want to print every single line of your file. So, it kind of works like a "grep" in the sense that, if you end your sed statement with the "p" flag and use -n, you will only print the lines that match.

So, for instance:

sed -n '/HELLO/p' filename
would only print the lines from "filename" that matched the regular expression HELLO.

I think if you just add the p to the end of your expression (works on straight-up match operator, like above, and at the end of a substitute, like you're doing (e.g. sed -n 's/this/that/p' FILE)

Best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC