Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Newbie help with sed

Newbie help with sed

Newbie help with sed

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.

RE: Newbie help with sed

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...

RE: Newbie help with sed

btw, for completeness's sake:
do not (-n) print other lines

RE: Newbie help with sed

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.

RE: Newbie help with sed

Quote (pavNell):

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.

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)


"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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close