Here’s a long-standing question of mine for which I can’t find a satisfying solution.
Let’s say that you have a file for which contains N whitespace-delimited columns and an additional column which have spaces in it that you want to keep.
Example with N = 2:
1.1 1.2 data for row1
2.1 2.2 data for row2
? ? data for row3
* data for row4
I would like to output:
data for row1
data for row2
data for row3
data for row4
In the shell you can do it easily with:
while read -r _ _ data
do
printf "%sb" "$data"
done < data.txt
But with awk
it’s kind of difficult? Is there a method in awk
for splitting only the first N columns?