| | |
Beginner in UNIX/Shell Script - Please help
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
•
•
Join Date: Nov 2008
Posts: 6
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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:
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
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
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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: difference btw a process and a job
- Next Thread: IPV6
| Thread Tools | Search this Thread |





