Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie help with sed

Status
Not open for further replies.

bluegroper

Technical User
Dec 12, 2002
407
0
0
AU
Hey forum
I've not used sed much.
When I pipe a text file to
| sed -n '4,$p'
What does sed actually do to the file ?
man sed did not help me at all.
TIA's


 
Why don't you try with a few files and find out yourself? [wink]

ok, here you go:
print (p) from fourth (4) to last ($) line.

I agree that reading man sed isn't easy. But it's worth it...
 
btw, for completeness's sake:
do not (-n) print other lines
 
Actually, it doesn't to anything to the text file. It just prints the results of the command to the screen. Also piping a text file into sed is not the most efficient way to use sed. Here's a better example and also overwrites the input file. Make a copy of text file first in case you screw it up.

line=`sed -e '4,$p' textfile.txt.bak 2>/dev/null`
echo "$line" > textfile.txt.bak

Hope this helps.
 
pavNell said:
Also piping a text file into sed is not the most efficient way to use sed.
Piping stuff into sed is efficient enough for most purposes. Unless you've actually got a performance problem, don't fix it. It just obfuscates what you are trying to do.


[rant]
Personally, I can't stand all those bash/korn scripts that are constantly shelling out to cut, sed, awk, and echo just to get the job done. If your scripting language can't cut it on it's own, pick one that can (hint: Perl)
[/rant]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top