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

king of the parse errors {}, if, variables...

Status
Not open for further replies.

bassfass

IS-IT--Management
May 22, 2003
5
US
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
}
 
This is not tested but should get you closer.

BEGIN {
prev = 0
out = 0
base = "out"
}
}
if($1 != prev){
out++
fn = base out
prev = $1
}
print >> fn
}

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
still gets me parse errors starting with "if" (once I removed the unbalanced "}")
the delimna goes on
 
Sorry, I had a closing brace instead of an opening one.

BEGIN {
prev = 0
out = 0
base = "out"
}
{
if($1 != prev){
out++
fn = base out
prev = $1
}
print >> fn
}

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
argggh
just realized that the unbalance "{" should've been a "{".
correceted that & I'm good to go. Thanks CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top