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!

How locate a field on a certain line

Status
Not open for further replies.

bholav

Technical User
Jun 13, 2002
15
US
How do I tell AWK to look for a certain "field" on a "certain" line

 
Bholav:

1) I'm using nawk on Solaris 7. You might have to use awk or gawk?

2) You didn't say what the field delimiter was. I assumed a default. If it's different uncomment out the other line and choose a proper value for FS.

Regards,


Ed


CF=2 # certain field
CL=3 # certain line
########nawk -v cf=$CF -v cl=$CL ' BEGIN { FS="|" }
nawk -v cf=$CF -v cl=$CL '
{
if(cl == NF)
printf("%s\n", $cf)

} ' input.file
 
Hi:

Man, let's try that again! Sorry:


1) I'm using nawk on Solaris 7. You might have to use awk or gawk?

2) You didn't say what the field delimiter was. I assumed a default. If it's different uncomment out the other line and choose a proper value for FS.

Regards,


Ed


CF=2 # certain field
CL=3 # certain line
########nawk -v cf=$CF -v cl=$CL ' BEGIN { FS="|" }
nawk -v cf=$CF -v cl=$CL '
{
if(cl == NR)
printf("%s\n", $cf)

} ' input.file
 
Also this:

awk -v n=lineno ' BEGIN
{
printf "Word to look for on %s:", lineno
getline var < &quot;-&quot;
}
{
if (NR == n) {
for (x=0 ; x <= NF ; x++) {
if ($x == var) {
print $x
}
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top