It is currently Mon, 27 Jun 2022 12:06:45 GMT

Author Message
 Extracting lines from inside a text file (question for sed expert)
I have a file that has this text (see below) in the middle.  What I
need to do is extract the text "Replace 'reboot' command ..." from it.

I used this sed command to get the output to start at the word

                sed -n '/versions:/,$p'

What I need now is to get sed to start outputting text 5 lines after
it finds "versions:".  Then it needs to stop right before the line
that has "notReady" in as the 4th word in the line.

Can anyone tell me how to do that?

  user     date       SID                        
  -------- ---------- ----------------------------

  timur    2003/04/30 1.2                          notReady
Replaced 'reboot' command with message to reset the FSP.

  fspbld   2003/04/02 1.1                          notReady
Initial Version

 Mon, 17 Oct 2005 23:39:39 GMT   
 Extracting lines from inside a text file (question for sed expert)

following your specification to the letter gives:

  sed -n '
      /^  *[^ ][^ ]*  *[^ ][^ ]*  *[^ ][^ ]*  *notReady/q
      b a

i.e. once "versions:" is found, read four lines, being a loop, read a line,
if it is the line that has "notReady" in as the 4th word, quit, else
print that line and loop.

now, given how your file looks, it is perhaps easier to just
print everything between two notReady, quitting at the first blank line:

  sed -n '
      p;/^ *$/q


 Tue, 18 Oct 2005 00:05:08 GMT   
 Extracting lines from inside a text file (question for sed expert)

How do I get this on one line.  I'm trying to pipe the output to grep,
but I get an error:

[root@timur bin]# File -long -view src/menu/cgi/menuindex.C -release
fips | sed -n '/notReady/,/notReady/{p;/^ *$/q}'
sed: -e expression #1, char 32: Extra characters after command

 Tue, 18 Oct 2005 05:43:00 GMT   
 Extracting lines from inside a text file (question for sed expert)

you don't *need* to get it all on one line. However if you really want,
try adding semicolons after q (and perhaps also after {, though POSIX
sed shouldn't need it):

  ... | sed -n -e '/notReady/,/notReady/{p;/^ *$/q;}'


 Tue, 18 Oct 2005 15:46:29 GMT   
   [ 4 post ] 

Similar Threads

1. Extracting lines from a text file that match a certain criteria to another text file

2. Find First Match Using SED and Then Extract Text from Line

3. Extract specific text from file using sed

4. help with sed extracting email address from text file

5. sed: extracting single field from each line of a CSV file

6. How to extract very 1st line of a file with sed or any:

7. Urgent, need script or command to extract lines from a huge text file

8. Extract different lines from a text file

9. sed - delete first line of text file

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software