![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Split a file with no pattern -- Split, Csplit, Awk | madhunk | UNIX for Dummies Questions & Answers | 10 | 12-17-2007 12:57 PM |
| perl - how do i find out if a file doesn't contain a pattern? | mjays | Shell Programming and Scripting | 4 | 09-19-2007 07:28 AM |
| multiple pattern split in perl | umen | Shell Programming and Scripting | 3 | 08-01-2006 03:43 AM |
| perl pattern matching vs. grep | junkmail426 | Shell Programming and Scripting | 0 | 09-28-2005 11:40 AM |
| awk script to split a file based on the condition | superprogrammer | Shell Programming and Scripting | 12 | 06-14-2005 04:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Split a file based on pattern in awk, grep, sed or perl
Hi All,
Can someone please help me write a script for the following requirement in awk, grep, sed or perl. Code:
Buuuu xxx bbb Kmmmm rrr ssss uuuu Kwwww zzzz ccc Roooowwww eeee Bxxxx jjjj dddd Kuuuu eeeee nnnn Rpppp cccc vvvv cccc Rhhhhhhyyyy tttt Lhhhh rrrrrssssss Bffff mmmm iiiii Ktttt eeeeeee Kyyyyy iiiii wwww Rwwww rrrr sssss eeee Rnnnnn xxxxxxccccc file1: Code:
Buuuu xxx bbb Kmmmm rrr ssss uuuu Kwwww zzzz ccc Roooowwww eeee Code:
Bxxxx jjjj dddd Kuuuu eeeee nnnn Rpppp cccc vvvv cccc Rhhhhhhyyyy tttt Lhhhh rrrrrssssss Code:
Bffff mmmm iiiii Ktttt eeeeeee Kyyyyy iiiii wwww Rwwww rrrr sssss eeee Rnnnnn xxxxxxccccc Appreciate you help. Thanks Kumar Last edited by Yogesh Sawant; 06-20-2008 at 04:25 AM.. Reason: added code tags |
|
||||
|
Quote:
Try this: Code:
awk '/^B/{close("file"f);f++}{print $0 > "file"f}' file
|
|
||||
|
thank you all
All solutions really worked great. Now I have a choice. Thanks. Appreciate your help.
awk '/^B/{close("file"f);f++}{print $0 > "file"f}' input.txt perl -n -e '/^B/ and open FH, ">output_".$n++; print FH;' input.txt csplit -k input.txt '/^B/' '{99}' |
![]() |
| Bookmarks |
| Tags |
| linux, solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|