I've got a file that I want to split out by value of field 1.
I'm trying to say "print the first line out to a new file called 'out1', go to the next line & compare the value of $1 with that of the previous line, if value is the same append this line to that file, if different create a newfile 'out2', and so on creating as many files as different values of field 1."
sounds simple but newbee that I am to gawk (windows 2000 os) I feel like a bull in a china shop. suggestions are appreciated.
here's what I've been running that gets parse errors upda @$$ beginning with the if statement
BEGIN {
prev = 0
out = out
}
if($1 !== $prev){
out = ++out
print > $out
prev = $1
}
else
{
print >> $out; prev = $1
}
I'm trying to say "print the first line out to a new file called 'out1', go to the next line & compare the value of $1 with that of the previous line, if value is the same append this line to that file, if different create a newfile 'out2', and so on creating as many files as different values of field 1."
sounds simple but newbee that I am to gawk (windows 2000 os) I feel like a bull in a china shop. suggestions are appreciated.
here's what I've been running that gets parse errors upda @$$ beginning with the if statement
BEGIN {
prev = 0
out = out
}
if($1 !== $prev){
out = ++out
print > $out
prev = $1
}
else
{
print >> $out; prev = $1
}