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

Reading the third file and sub 3

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

Below is the code which I am busy with but am stuck with trying to read the third file.
What I would like to do is to use (this value------->) as indicated below and sub into the third file
Can anyone assist me with this issue.

awk 'FNR==NR {
a[$3,$4,$5,$6]=$2
next
}
{
idx=$1 SUBSEP $5 SUBSEP $11 SUBSEP $12
if ( idx in a) {
$2 = a[idx]
this value-------> print $2
}
}' database $1.temp

Many Thanks
Chris
 
Take the ' out of this line:

[tt]# We're reading the 3rd file.[/tt]

If you are using awk ' yourscript ' the extra apostrophe terminates it prematurely.

Annihilannic.
 
Hi Annihilannic,Futurelet

Thanks Again. It was the apostrophe. I understand where you going at with the script but I get an empty file output. How can I see that it is reading the Third file.

Thanks
Chris
 
Anything but 0 (ie False)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi all,

I see all the gurus are back, Thanks.
I still get an output of "0"file size. If I place a print for the output of a[dix] I see the result. What next???

+ awk -v File=rjs+:01.01413574.20060124110007._1.err -v opt=1 -v Num=6 -v Num2= -v Num3=D '

# The first file on the command line has 6 fields.
# Reading first file?
ARGV[1]==FILENAME {
a[$3,$4,$5,$6] = $2
next
}

# The 2nd file on the command line has 12 fields.
ARGV[2]==FILENAME {
idx = $1 SUBSEP $5 SUBSEP $11 SUBSEP $12
if ( idx in a)
list[ ++count ] = a[ idx ]
next
}

# Were reading the 3rd file.

FNR == 1 { count = 0 }

/^(128|248|129) A/ { target = FNR + opt }

FNR == target {
replacement = list[ ++count ]
$1 = length ( replacement )
$2= replacement
$3="A"
}
8 ' database rjs+:01.01413574.20060124110007._1.err.temp


Many Thanks
Chris
 
8 to break the monotony of 1. Even "Hi, Mom!" would work, of course.

The problem you had with the apostrophe (') illustrates why it is best to put the awk program in a separate file and run it this way:
Code:
awk -v opt=1 -f sub_file3.awk foo.txt bar.txt baz.txt
 
Replace this:
8 ' database rjs+:01.01413574.20060124110007._1.err.temp
with this:
8 ' database rjs+:01.01413574.20060124110007._1.err.temp rjs+:01.01413574.20060124110007._1.err

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You must give awk 3 filenames. ARGV must contain three filenames. Example:
Code:
awk -v opt=1 -f sub_file3.awk foo.txt bar.txt baz.txt
Don't attempt to provide a file to awk by
[tt]-v File=rjs+:01.01413574.20060124110007._1.err[/tt].
We're not using [tt]getline[/tt]. We're letting awk read all of the lines automatically. (Always avoid getline if you can.) The first file on the command line must be the file that has 6 fields per line.
 
Hi Gurus,

What I site and guys. I could be like yours one day if you are willing to keep helping me in this way. Anyway many thanks for all your help and patience. Thanks

Futurelet or PHV
1)Will it be possible to explain to me from the piont of reading the third file.
2)Why when I put in a "print list[ ++count ]" no print mesg is printed but if you put a print a[idx] it prints.

Many Thanks to all
Chris
 
You would have to remove the "++" from "print list[ ++count ]"; otherwise you would make [tt]count[/tt] invalid.

Here's the last part of the program with a few added comments:
Code:
# We're reading the 3rd file.

# If we've just read the 1st line, set count to 0
# so that we can step through the list.
# FNR is the number of the record (or line) in this file;
# NR is the number of records read from all the files.
FNR == 1  { count = 0 }

/^(128|248|129) A/  {  target = FNR + opt }

FNR == target {
  replacement = list[ ++count ]
  $1 = length( replacement )
  $2 = replacement

  #-------
  #------- For debugging only!
  #-------
  print ">>> " list[ count ] " <<<"  > "/dev/stderr"

}

# Print the line.  Any true value will work.
8
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top