sed -rn '
/\S+,\S+,\S+,\S+/{p;b} # if all four columns exist, print and branch to end
s/^([^,]+).*/\1/ # else extract first column
h # hold
s/.*/echo output &/e # exeute external command echo with first column as argument
G # append previous hold value
s/(.*)\n(.*)/\2,\1/ # arrange position
p' file # print result
В awk
:
awk '{ for (i = 1; i <= $1; i++) { print $0 } }' file > newFile
Это прочитает входной файл один раз и один раз запишет выходной файл, и вам никогда не придется ничего повторно открывать.
В perl
, используя оператор повторения строки x
:
$ perl -ne 'print $_ x $_' file
1
1
2
2
3
3
3
2
2
4
4
4
4