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

FILE SPLITING PROBLEM

Status
Not open for further replies.

tgopalakrishna

Programmer
Jul 16, 2004
5
US
Hi,

I want to split a data file using AWK on the 3rd Filed Value(Date Field). Can some one please help me?

Thanks
Gopal
 
What are you meaning with spliiting on the 3rd field ?
Can you please post input data and expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
2000011|PPS_OWNER|2004-07-14 00:00:00|100|50|0||0||0||0||0||0||0||0||0||MTR_COMMENT|1|2|25|15|||||||||||10|1|||

303100005|PPS_OWNER|2004-07-14 00:00:00|100|50|0||0||0||0||0||0||0||0||0||MTR_COMMENT|1|2|25|15|||||||||||10|1|||


I have just pasted 2 record from my data file, the file is seperated by | and the 3rd field is a date field, I will have millions of records in this file, I want to split this file whenever the Value of DATE field(3rd field) changes.

Thanks
Gopal
 
Something like this ?
awk -F'|' '{print >"out"$3}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi Thanks for your reply, But i want to print all the records with the same date into one file, whenever the date value changes i have to write it into a new file? can you please tell me the solution for this?

Thanks
Gopal
 
Have you just tried my suggestion ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi

Basically i am a SAS programmer and i am new to AWK, i could not understand what to keep in place of OUT, do i have to give the output file name here?

when ever the date value changes i want to generate a new file exmaple : outfile1, outfile2 .....

Can you explain me how this works?

Sorry for bothering you

Thanks
Gopal
 
print >"out"$3
write the two lines to file named "out2004-07-14" with your example.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi

Now I understood the FileName part of your code, thank you very much for explaining, but my Dumb brain could not understand how will this script Split the file whenever the Date field value changes (we have not mentioned any condition!), I am sorry if am irritating you, but please help me

Thanks
Gopal
 
The splitting will occurs each time $3 (the 3rd field) will change.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
phv's way is ok, use >> instead of >
if you have "millions of records", probably also get
memory troubles using awk, due to the way awk works:
it read and split the whole file in memory. so i would
prefer a 20line own c-code sequential working line by line.
 
phv
> will overwrite the output-file
he has millions of records...
so the last is keept, all oder lost :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top