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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I would like to save certain lines of a file to another file.

Status
Not open for further replies.

buckpasser

Technical User
Mar 10, 2005
24
US
Folks,

I would like to save (parse out) certain lines of a file and save them to another file.

==================INPUT======================

--Garbage Lines--

--Keyword A------

--Garbage Lines--

#Keyword B ------
--Save Lines--------
--Save Lines--------

--Garbage Lines--

--Keyword A------

--Garbage Lines--

#Keyword B ------
--Save Lines--------
--Save Lines--------

--Garbage Lines--
====================OUTPUT===========

--Keyword A--
#Keyword B ------
-----Save--------
-----Save--------

--Keyword A--
#Keyword B ------
-----Save--------
-----Save--------

 
Hi feherke

Sections are delimited by a BLANK LINE.

Keywords are fixed.

Thanks
 
Hi

Still not too clear. As I understand your question, the answer should be something like this :
Code:
sed -n '/Keyword/,/^$/p' inputfile > outputfile
[gray]# or[/gray]
awk '/Keyword/,/^$/' inputfile > outputfile
But you already know this from thread80-1135120 of forum80.

Feherke.
 
Hi Feherke,

The Keywords are fixed but different. Hence Keyword A and Keywork B.

Basically I want to grab the lines that contain Keyword A and follow with the range of lines starting with #Keyword B to the BLANK LINE.

Hope this helps.

Thanks
 
Perhaps this ?
awk '
/Keyword A/{print;next}
/Keyword B/,NF==0
' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top