0

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
Mihir
  • 557
  • 1
  • 6
  • 28
  • I was able to get desired output using python. I'm not sure if there is any way to get desired output using bash. https://stackoverflow.com/questions/18412179/reading-a-file-and-storing-values-into-variables-in-python – Mihir Oct 29 '18 at 20:03

1 Answers1

1

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?

Paul Hodges
  • 13,382
  • 1
  • 17
  • 36
  • this is what i was looking for.. Thank you @Paul Hodges – Mihir Oct 30 '18 at 11:55
  • is there any easier way to apply same logic using python? – Mihir Feb 01 '19 at 16:40
  • Python not my forté, but I'm sure there is. Post another question, tag it with Python to get the attention of the experts, and link it back to this question for reference. :) – Paul Hodges Feb 04 '19 at 14:24