Operating System - HP-UX
1755680 Members
5653 Online
108837 Solutions
New Discussion юеВ

Re: sed cmd to find a constant and get ALL lines after it

 
SOLVED
Go to solution
S.Rider
Regular Advisor

sed cmd to find a constant and get ALL lines after it

I'm looking to pull all the "Special Installation Instructions" out of a bunch of PH*.text files. This information starts with the header :Special Installation Instructions" and has a varying number of lines but it always the last section of the file.
cat PHSS_37232.text | sed -n -e '/^Special Installation Instructions/{N;N;N;p;}'
will get me 3 lines but is there a way to tell it to give me all the remaining lines in a file ?
Ride Boldly Ride, but watch out for El Dorado's
9 REPLIES 9
Arunvijai_4
Honored Contributor

Re: sed cmd to find a constant and get ALL lines after it

A good tips on using "sed"
http://www.student.northpark.edu/pemente/sed/sed1line.txt

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Pete Randall
Outstanding Contributor

Re: sed cmd to find a constant and get ALL lines after it

From "Handy One-Liners for SED" (attached):

# print paragraph if it contains AAA (blank lines separate paragraphs)
# HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'


Pete

Pete
Kent Ostby
Honored Contributor
Solution

Re: sed cmd to find a constant and get ALL lines after it

Use awk.

create a file called useme.awk

BEGIN{daflag=0;}
/^Special Installation Instructions/{daflag=1;}
daflag==1 {print $0}

Then what you do is:

awk -f useme.awk < my_patch_file
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Mel Burslan
Honored Contributor

Re: sed cmd to find a constant and get ALL lines after it

it may not be the sed only solution but this does what you need (and it still uses sed)

LINE=`grep -n "Special Installation Instructions" PHSS_37232|cut -d: -f1`

cat PHSS_37232|sed -e "1,${LINE}d" > PHSS_37232.meat

2 lines instead of one for simplistic understanding. they can be combined into a single line if needed by command substitution.

HTH
________________________________
UNIX because I majored in cryptology...
Rodney Hills
Honored Contributor

Re: sed cmd to find a constant and get ALL lines after it

How about-

cat PHSS_37232.text | sed -n -e '/^Special Installation Instructions/,999999p'

Just put a large number for the ending line number.

HTH

-- Rod Hills
There be dragons...
Pete Randall
Outstanding Contributor

Re: sed cmd to find a constant and get ALL lines after it

Actually I didn't read your request carefully enough. To print to the end of the file you would want to use this one:

# print section of file from regular expression to end of file
sed -n '/regexp/,$p'


Pete

Pete
H.Merijn Brand (procura
Honored Contributor

Re: sed cmd to find a constant and get ALL lines after it

# perl -ne'/^Special Installation Instructions//..eof and print' PHSS_37232.text

or more evil

# perl -pe'/^Special Installation Instructions//..eof or$_=""' PHSS_37232.text

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
David DiBiase
Frequent Advisor

Re: sed cmd to find a constant and get ALL lines after it

you didn't ask about how to loop thru the list of files so I restrict my answer to sed. The command you would use within the loop is
sed -e '/^Special Installation Instructions/,$p' < [input file] > [output file]
OR
for file in `ls PH*`
do
sed -e '/^Special Installation Instructions/,$p' <${file} > ${file}.spcl
done

pls excuse the typo's - sitting in an airport waiting for the red-eye
David DiBiase
Frequent Advisor

Re: sed cmd to find a constant and get ALL lines after it

sorry - forgot to type -n -e NOT just -e
see - i told you i was tired ;-)