Mihir
Mihir

Reputation: 557

bash reading multiple text file and setting variables

how can read each lines and then set each string as separate variables.

for example:

555 = a
abc = b
5343/abc = c
22 = d
2323 = e
233/2344 = f

test1.txt

555 abc 5343/abc
444 cde 343/ccc

test2.txt

22 2323 233/2344
112 223 13/12

echo $a $d $f

desired output:

555 22 233/2344
444 112 13/12

Following script will set each line as variable but i would strings in each line as variable.

paste test1.txt test2.txt | while IFS="$(printf '\t')" read -r f1 f2
do
  printf 'codesonar %s %s\n' "$f1 $f2"

done

Upvotes: 0

Views: 94

Answers (1)

Paul Hodges
Paul Hodges

Reputation: 15293

You have to use the variables you want in your read.

$: paste test1.txt test2.txt |
> while read a b c d e f g h i j k l m n o p q etc
> do echo $a $d $f
> done
555 22 233/2344
444 112 13/12

Am I missing something?

Upvotes: 1

Related Questions