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

grep lines between spaces in a file.

Status
Not open for further replies.

SDCSA

Programmer
May 8, 2003
22
US
Hi,

I would like to take a file, grep blocks of lines between spaces and spool them to a different file . Suppose that the file name is a.txt, I'd like to create a1.txt, a2.txt depending on the number of text blocks between spaces. Will appreciate if anyone can suggest me how to do this.

aaaaaaa
aaaaaaa

bbbbbb
bbbbbb

Thanks.
 
What have you tried so far and where in your code are you stuck ?
Tip: man awk

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
feherke, which *nix has a csplit admitting the -b option ?
Well, GNU csplit admits it, I guess.
 
So, here a legacy portable approach:
Code:
awk 'BEGIN{a=1}NF{print >("a"a".txt");next}{close("a"a++".txt")}' a.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top