Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!ucsd!network.ucsd.edu!weber!pbiron From: pbiron@weber.ucsd.edu (Paul Biron) Newsgroups: comp.unix.questions Subject: Re: How to merge two files in awk?? Message-ID: <4555@network.ucsd.edu> Date: 1 Feb 91 16:15:18 GMT References: <3404@d75.UUCP> <1070@mwtech.UUCP> Sender: news@network.ucsd.edu Reply-To: pbiron@weber.ucsd.edu (Paul Biron) Organization: Division of Social Sciences, UCSD Lines: 45 Nntp-Posting-Host: weber.ucsd.edu In article <1070@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: >In article <3404@d75.UUCP> @xlab1.uucp () writes: [stuff deleted] >> Finally, how do u specify the "rest of the line" in awk?? > >I don't quite understand this. Do you mean the following: > > 33.5 ZZZ 4564.334 foo bar > ^^^^^^^--- processed as "rest of line" > ^^^^ ^^^ ^^^^^^^^ ---------- processed as $1, $2, $3 > >first three fields always occupy the same space, say 18 chars, you >can access the "rest of line" as substr($0, 19). > >If the $1..$3 have no equal witdh, but you are sure that there is >only one separator between them, you may sum them up and get the rest >of the line with substr($0, length($1) + length($2) + length($3) + 3). > [stuff deleted] Another, albeit data dependent, way to do "rest of line" in {n,g}awk is the following: #!/usr/local/bin/gawk -f { start = index ($0, $3) print "first is", $1, $2 print "rest is", substr ($0, start) } This assumes that what you want to process as the "rest of line" does not occur in the "first" part of the line. While in general I agree with Martin that structuring your input data makes your life a lot easier when it comes to writing awk scripts, however, that is not always possible. I don't know wheter it *is* possible in the case of the original poster. Hope this helps, -------------------------------------------------------------------------------- STOP THE WAR IN THE GULF --- NOW !!!!!!! -------------------------------------------------------------------------------- Paul Biron pbiron@ucsd.edu (619) 534-5758