Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Process two...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 10 Topic 2151 of 2317
Post > Topic >>

Re: Process two files simultaneously

by Ed Morton <morton@[EMAIL PROTECTED] > Feb 7, 2008 at 12:45 AM

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.
 




 10 Posts in Topic:
Process two files simultaneously
Combatwombat <combatwo  2008-02-07 15:35:34 
Re: Process two files simultaneously
Ed Morton <morton@[EMA  2008-02-07 00:45:51 
Re: Process two files simultaneously
Combatwombat <combatwo  2008-02-07 20:45:48 
Re: Process two files simultaneously
Ed Morton <morton@[EMA  2008-02-07 08:01:22 
Re: Process two files simultaneously
Combatwombat <combatwo  2008-02-08 03:46:46 
Re: Process two files simultaneously
Janis Papanagnou <Jani  2008-02-07 19:35:34 
Re: Process two files simultaneously
Combatwombat <combatwo  2008-02-08 09:53:59 
Re: Process two files simultaneously
Ed Morton <morton@[EMA  2008-02-07 14:59:43 
Re: Process two files simultaneously
"Luuk" <luuk  2008-02-07 10:27:08 
Re: Process two files simultaneously
Janis <janis_papanagno  2008-02-07 04:44:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:26:06 CDT 2008.