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

Scritp to split a flat file into 2 different ones 1

Status
Not open for further replies.

Yanndewael

Programmer
Mar 14, 2003
12
GB
Hello,

I'd like to write a script to read a flat file and to split it into 2 different ones. Here is the structure of the original file:
0xxxxxxxxxxx
1xxxxxxxxxxx
1xxxxxxxxxxx
...
9xxxxxxxxxxx
0xxxxxxxxxxx
1xxxxxxxxxxx
...
9xxxxxxxxxxx

Where x can be a number or a letter and where the number of line beginning with "1" is variable.
I want have 2 files, each beginning with the "0" line and finishing with the "9" line -->

File 1:
0xxxxxxxxxxx
1xxxxxxxxxxx
1xxxxxxxxxxx
...
9xxxxxxxxxxx

File 2
0xxxxxxxxxxx
1xxxxxxxxxxx
...
9xxxxxxxxxxx

Any idea??
Thank you in advance!
Yann
 
something like that:

nawk -f split.awk myFile.txt

#--------------------- split.awk
BEGIN {
filePrefix="file"
fileCnt=0
}

{
if (int(substr($1,1,1)) == 0) fileCnt++;
file=filePrefix fileCnt;
print >> file
}
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
i dont reaaly understand your Q, but this could help:
sed -e '/^0/,/^9/{
w fileA
/^0/,/^9/w fileB
}' inputfile
UNTESTED.
 
Hello,
I have a file that has the following pattern throught out the file

export -c test -n &quot;test2201/10003.199990203.1444.MO&quot; -f &quot;test2201/10003.199990203.1444.MO&quot;

The above is on one line. What I need is to change the &quot;/&quot; in the second occurrence, i.e. the one after f which is marked red to _ I was wondering if sed or awk can be used to do that.

Regards,

Ziad
 
Hello,

Please ignore my last message, I thought I started a new thread

Regards,

Ziad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top