say we have a tsv file
1 2 3
1 2 3
we want to do some operation say echo $1 $2 $3
for each tsv file line.
How to do such thing in bash?
This can make it:
while read -r a b c
do
echo "first = $a second = $b third = $c"
done < file
$ while read -r a b c; do echo "first=$a second=$b third=$c"; done < file
first=1 second=2 third=3
first=1 second=2 third=3
As the separator is a tab, you don't need to use IFS
. If it was for example a |
, you could do:
$ cat file
1|2|3
1|2|3
$ while IFS='|' read -r a b c; do echo "first=$a second=$b third=$c"; done < file
first=1 second=2 third=3
first=1 second=2 third=3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With