Assuming you have the following SSV file
cat file | while read line; do
echo "$line"
done
1 hoge foo piyo
2 hoge foo piyo
3 hoge foo piyo
↑ Assign this content to a variable for each column ** and process **.
#Try to output the 1st and 2nd columns
cat file | while read col1 col2 col3 col4; do
echo "$col1" "$col2"
done
1 hoge
2 hoge
3 hoge
With the above, isn't it necessary to define col3 and col4? In such a case, store it in a variable and throw it away.
cat file | while read col1 col2 x; do
echo "$col1" "$col2"
done
1 hoge
2 hoge
3 hoge
#Take a look at the contents of x
cat file | while read col1 col2 x; do
echo "$col1" "$col2" "x:$x"
done
1 hoge x:foo piyo
2 hoge x:foo piyo
3 hoge x:foo piyo
#If you want only the 1st and 3rd rows
cat file | while read col1 x col3 y; do
echo "$col1" "$col3" "x:$x y:$y"
done
1 foo x:hoge y:piyo
2 foo x:hoge y:piyo
3 foo x:hoge y:piyo
Recommended Posts