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!

divide one file in other

Status
Not open for further replies.

tonivm

Technical User
Mar 2, 2006
64
ES
Hi everybody:
Could anybody tell me how i could divide from a file which has got diferent fields, where there is a field that repeat any times ($3), and i'd like divide this file in others when this field will change.

20050727 0751 208 7,55154 0,29775 492,0 1,000 177,00 0,000
20050727 0752 208 7,5682 0,30073 502,0 3,000 177,00 0,000
20050727 0753 208 7,58487 0,30370 508,0 1,000 178,00 0,000
20050727 0754 208 7,60154 0,30666 511,0 0,000 177,00 0,000
20050727 0755 208 7,6182 0,30962 516,0 2,000 177,00 0,000
20050727 0756 208 7,63487 0,31258 524,0 2,000 176,00 0,000

thanks in advance
 
A starting point:
awk '{print > "/path/to/out"$3".txt"}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for your reply, but your help doesn't work correctly as i'd like.
I ask, how could i divide one file in others when a field that repeat any times, when changes its value save in other file:

For exemple, the original files is:
$1 $2 $3 $4 $5 $6 $7 $8 $9
20051223 0846 357 8,59875 0,16341 178.1 0.989 52.68 0.143
20051223 0847 357 8,61542 0,16572 180.4 0.567 53.2 0.188
20051223 0848 357 8,63209 0,16802 182.5 0.489 53.59 0.107
20051223 0849 357 8,64875 0,17031 184.7 0.71 53.89 0.128
20051223 0850 357 8,66542 0,17260 187 0.757 54.31 0.143
20051224 0000 358 -0,175686 -0,94734 -0.644 0 -0.31 0.106
20051224 0001 358 -0,159019 -0,94747 -0.644 0 -0.264 0.09
20051224 0002 358 -0,142352 -0,94759 -0.644 0 -0.242 0.073
20051224 0003 358 -0,125686 -0,94769 -0.644 0 -0.256 0.085
20051224 0004 358 -0,109019 -0,94778 -0.644 0 -0.239 0.069
..................
..................
..................
..................

i'd like save in differents files when the field $3 change (in this case from 357 to 358, both in two files with the name $1.csv)

Thanks in advance
 
Hi

From my point of view PHV's code does exactly what you asked for, just need to change the filename. And works fine with [tt]gawk[/tt] and [tt]mawk[/tt].

If you still not like the result, think that is possible that your question was not clear enough. Try to post some expected result file samples.

Feherke.
 
Thanks and sorry but in first time i didn't understand PHV's code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top