0

i have an awk command as below :

awk 'FNR==NR{a[$1$2]=$3;next} ($1$2 in a) {print$1,$2,a[$1$2],$3}' ""each line of file 1""  >./awkfile/12as_132l.txt

and f1.txt content is :

1sas.txt 12ds.txt 
13sa.txt 21sa.txt

i want that my script read each line of fil1.txt and put the contents in this awk command...instead of """each line of file1"".. and execute the command like below:

    awk 'FNR==NR{a[$1$2]=$3;next} ($1$2 in a) {print$1,$2,a[$1$2],$3}'  1sas.txt 12ds.txt  >./awkfile/12as_132l.txt



  awk 'FNR==NR{a[$1$2]=$3;next} ($1$2 in a) {print$1,$2,a[$1$2],$3}' 13sa.txt 21sa.txt  >./awkfile/12as_132l.txt

i need a loop but the problem is that's a little strange for me .

2 Answers 2

1

Here is Snippet, which reads 2 fields line by line from f1.txt, put it into variable, and used in awk

#!/usr/bin/env bash

while read -r  col1file col2file; do

       # your command goes here
       # this awk does nothing, replace it with your command
       awk '{  }' "$col1file" "$col2file" > someoutfile 

done < "f1.txt"

Test Results:

akshay@db-3325:/tmp$ cat f1.txt 
1sas.txt 12ds.txt 
13sa.txt 21sa.txt

akshay@db-3325:/tmp$ cat test.sh 
while read -r  col1file col2file; do

       echo "col1 : $col1file"
       echo "col2 : $col2file"

       # your command goes here
       # this awk does nothing, replace it with your command
       # awk '{  }' "$col1file" "$col2file" > someoutfile 

done < "f1.txt"

akshay@db-3325:/tmp$ bash test.sh 
col1 : 1sas.txt
col2 : 12ds.txt
col1 : 13sa.txt
col2 : 21sa.txt
Sign up to request clarification or add additional context in comments.

Comments

0
change the IFS to IFS=' ' and use loop .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.