Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
what i have to do is use sed to delete from line 1 to the line that contains 'Second'.
i can do this with the following which works just as expected:
$ cat myFile | sed 1,/'Second'/d
however, my problem is that i have to use sed with a -n option for other reasons, so it looks like:
$ cat myFile | sed -n 1,/'Second'/d
This does not print the output because of the -n option.
if i append /p to it:
$ cat myFile | sed 1,/'Second'/d/p
it results in error. this is probably a small syntax thing i'm missing, but i can't figure out what it is. i've tried the /p thing many ways, but it just doesn't work.
thanks. that approach helps me... there's just one slight thing extra that i was trying to do with my previous approach, and that is not to print the line 'Second'. is there a way to do that?
i'm using -n because i'm writing a sed script file that will receive a very large file as an input, i want to print only sections of the file.
I wold recommend forming the habit of enclosing the whole sed program string in single quotes. They you can use spaces within it and very much improve readability. Multiple commands can be separated with semi-colons:
My first thought was: sed -n '/The Third/,$p' myFile. But I doubt that the myFile example given in your first post is accurate.
Maybe you could post a relevant part of the myFile (replacing possible privacy sensitive stuff) and give us a larger view of what it is you are trying to do.
About the -n option: As you probably found out the -n (suppress normal output) and p (print current pattern space) option kinda go together and is probably what you want to use to cut out parts of the large infile.
... You might want to do this is you have a very massive file and don't have room to create a temp file for the output.
One needs to be careful here if one is cramped for space: my version of sed will create the temporary file itself if this option is specified:
Quote:
`-i[SUFFIX]'
`--in-place[=SUFFIX]'
This option specifies that files are to be edited in-place. GNU
`sed' does this by creating a temporary file and sending output to
this file rather than to the standard output.(1) ...
-- excerpt from info sed
The in-place term is something of a misnomer here, because it refers to the final result, not the mode of operation ... cheers, makyo
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.