user3784040
user3784040

Reputation: 111

Read every line of file in bash and awk

I have a file(test.txt) which has contents like

/the/path/foo.txt  foo.txt 
/the/paths/doo.txt  doo.txt 
/the/path/foo.pl  foo.pl 
/the/paths/doo.pl  doo.pl 
/the/path1/soo.csv  soo.csv
/the/path2/moo.csv  moo.csv

I want to have awk {print $1} be saved to a variable1 and awk {print $2} be saved to variable2 in bash script i.e variable1 gets /the/path/foo.txt and variable2 gets foo.txt and so on

Thanks

Upvotes: 1

Views: 99

Answers (1)

jaypal singh
jaypal singh

Reputation: 77095

You can use read built-in to capture and assign fields to variables (assuming there are no spaces in your paths):

while read -r var1 var2; do
    # do something with variables
done < text.txt

Upvotes: 6

Related Questions