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)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0