Computing.Net > Forums > Unix > to split a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

to split a file

Reply to Message Icon

Name: nicolas
Date: August 21, 2003 at 03:08:42 Pacific
OS: ksh
CPU/Ram: ?
Comment:

Hello,

I have to split a fil in several parts. I need to cut it in blocks delimited by 2 particular lines. What is the best tool to do that ? (or can anyone give me a piece of programm that can do that)
Thank you for your help.

Nicolas



Sponsored Link
Ads by Google

Response Number 1
Name: cc0537
Date: August 21, 2003 at 05:51:44 Pacific
Reply:

read up on awk


0

Response Number 2
Name: James Boothe
Date: August 21, 2003 at 06:20:52 Pacific
Reply:

This program compares entire line ($0).  Instead, you can trigger on a certain field like if ($1=="HEADER"), or match any part of a line like if match($0,"part of the line").

#!/bin/sh

awk 'BEGIN \
{outfile="outfile1"}

{if ($0=="this line begins file2")
    outfile="outfile2"
 else
 if ($0=="this line begins file3")
    outfile="outfile3"
 else
 if ($0=="this line begins file4")
    outfile="outfile4"
 print > outfile
}' infile

exit 0


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: to split a file

Split a file into 2 files www.computing.net/answers/unix/split-a-file-into-2-files/7676.html

split a file with headers and trail www.computing.net/answers/unix/split-a-file-with-headers-and-trail/8235.html

How to delete a file named -x www.computing.net/answers/unix/how-to-delete-a-file-named-x/3350.html