![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk help with string spliting | RobertSubnet | Shell Programming and Scripting | 2 | 03-12-2009 02:11 PM |
| awk spliting using separator | PrasannaKS | Shell Programming and Scripting | 1 | 12-01-2008 04:23 AM |
| spliting 4gb files to 4*1 gb each | jambesh | Shell Programming and Scripting | 3 | 07-06-2008 02:50 PM |
| Help on Spliting files - urgent | rajee | Shell Programming and Scripting | 8 | 03-10-2008 01:01 PM |
| spliting up sentences | stevox | UNIX for Dummies Questions & Answers | 2 | 04-17-2001 04:36 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Spliting of two files
hi
I have a log file which contains some reports. The log file looks like this:- STARTOFREPORT /tmp file1.txt some text to be folowd ENDOFREPORT some non utilized characters STARTOFREPORT /log file2.txt more text to be folowd ENDOFREPORT blabla blak acd I want the text between STARTOFREPORT and ENDOFREPORT to be splited in two files i.e. file1.txt and file2.txt and stored at /tmp and /log location respectively. Please help as how to achieve this Thanks |
|
||||
|
I suppose one simple approach using awk: Code:
awk '
/STARTOFREPORT/ { getline PATH; getline FILE; p = 1; next }
/ENDOFREPORT/ { p = 0 }
p { print > PATH "/" FILE }
' input_file
> cat /tmp/file1.txt
some
text
to
be
folowd
> cat /log/file2.txt
more
text
to
be
folowd
|
|
||||
|
Thanks fro your reply.
It works perfect. just a little confusion. if the report contains STARTOFREPORT /path file.txt ENDOFREPORT no file is created at the location. Is there any way to create the file at the path, be it of 0bytes. Thanks |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|