18

I need to read the following input into separate columns as variables? input.txt

b73_chr10   w22_chr9
w22_chr7    w22_chr10
w22_chr8    w22_chr6

I have written the following command;but I guess it is not correct.

value1=$(echo $line| awk -F\ '{print $1}' input.txt)
value2=$(echo $line| awk -F\ '{print $2}' input.txt)
shome
  • 323

1 Answers1

29

You can use the read shell builtin:

while IFS=" " read -r value1 value2 remainder
do
    ...
done < "input.txt"

Extra fields, if any, will appear in 'remainder'. The shell's default IFS (inter-field-seperator) consisting of white space characters will be used to split each line into its component fields.

JRFerguson
  • 14,740
  • How to provide the file name in this syntax ? Like the filename(for e.g input.txt) in this syntax ? – shome Feb 08 '16 at 21:00
  • I've added input redirection to provide the name of the file to be read. – JRFerguson Feb 08 '16 at 21:08
  • I have another query..if you dont mind.I added this condition inside the loop: sed 's/$value1/$value2/g' circos.conf

    Is it correct to work ?

    – shome Feb 08 '16 at 21:17