On 2/6/2008 8:35 PM, Combatwombat wrote:
> ##ALERT!!!### Noobie struggling with Awk
>
> Hi all,
>
> I have a problem trying to figure out how Awk can process two input
> files simultaneously, as there is some reference on the web to it doing
> so, eg http://www.vectorsite.net/tsawk_3.html,
but it is short on detail
> and example. I am running Ubuntu 7.04 (gawk I think).
>
> Problem: take one csv file full of data, including one field that needs
> to be changed/processed on a regular, automatic, scalable basis. Take
> second csv file with data in two columns; first column = field matching
> data in first csv, second column = field of replacement data.
>
> So far I have:
>
> in Batch file:
>
> cat old.csv replacement.csv | awk -f awkins f1="old.csv"
> f2="replacement.csv" >> newfile
>
> awkins file:
>
> BEGIN { FS = ":" };{
>
> if($10 =="y"||$10=="Y"){ # begin process of extraction because
ALLOWSELL=y
> qty=$6+$8;
> if (($37 =="N"||$37=="n")&&qty<=0){
> status=9
> }else{ status=1;
> }
> {
>
> print $1," ",$1".jpg"," ",$1," ",$2," ","url"," ",$7," ",$7," ",qty,"
> ",$4," ",$5," ",status,"EOREOR";
>
> }
> }
> }
>
> I couldn't fihure out how to get Awk to look at the second file; getline
> worked with it , but filled the field variables with data from the
> second file.
> Thanks for any hints or help!
It's very hard to tell what it is you're trying to do. Posting some sample
input
and expected output would be a big help. In the meantime:
a) "getline" is almost certainly the wrong approach.
b) concatenating both files and setting awk variables with their names is
also
almost certainly the wrong approach.
c) let's start with this:
awk '{print FILENAME, $0}' old.csv replacement.csv > newfile
so you can see how you can run an awk script on multiple input files and
we'll
take it from there.
Ed.


|