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!

nawk with multiple files

Status
Not open for further replies.

uksnowman

Technical User
Apr 2, 2001
4
CH
Hi,

Is it possible to use one script to perform a different nawk processing sequence depending on the input file?
In order to use only one script to process several files with different formats.

For example, I cut the first 4 colums out of a log file, either a.txt or b.txt depending on which file is used then use nawk to parse the log.

#! /bin/sh

{
if (inputfile = a.txt)
cut -d" " -f1,2,3,4 a.txt
else
cut -d" " -f1,2,3,4 b.txt
fi
} | nawk '


BEGIN { (some pre-processing) }


if (inputfile = a.txt)
process1()
else if (inputfile = b.txt)
process2()

process1()
{
print hello
}

process2()
{
print goodbye
}

END { (some post-processing) }'


Any help will be great,

Thanks,
uksnowman
 
Hello, uksnowman!

You can use FILENAME built-in variable to perform a different awk processing depending on the input file.

Please, try this awk idea:

FILENAME == "a.txt" { print "a", $0 }

FILENAME == "b.txt" { print " b", $0 }


Bye!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top