Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Want to thank those people who have made this forum such a valuable place to visit each day..."

Geography

Where in the world do Tek-Tips members come from?

grep lines between spaces in a file.

SDCSA (Programmer)
30 Mar 12 10:07
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.
PHV (MIS)
30 Mar 12 10:11
What have you tried so far and where in your code are you stuck ?
Tip: man awk

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

feherke (Programmer)
30 Mar 12 10:17
Hi

Do you have csplit ?

CODE

csplit -f 'a' -b '%d.txt' a.txt '/^$/+1' '{*}'

Feherke.
http://feherke.github.com/

PHV (MIS)
30 Mar 12 10:36
feherke, which *nix has a csplit admitting the -b option ?
Well, GNU csplit admits it, I guess.
feherke (Programmer)
30 Mar 12 10:47
Hi

Oops, indeed, the SUS not specifies -b. So it is GNU extension.
Missed that. Thanks.

Feherke.
http://feherke.github.com/

PHV (MIS)
30 Mar 12 11:01
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: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close