On 2022-09-07 08:14, andalou wrote:
> If I use vim, how can I put the output after the data? as in:
> ----------
> 1001 John Sena 40000
> 1002 Jafar Iqbal 60000
> 1003 Meher Nigar 30000
> 1004 Jonny Liver 70000
> xx1001yyy, xx1002yyy, xx1003yyy, xx1004yyy
With the vim suggestions I gave, item #1 was to make a duplicate
copy of the data and then modify that:
>> I'd do it in two (or three) passes:
>> 1) optionally copy the data and paste it where you want the resuts
>> if you want to preserve it
like
:%t$
If so, you'd want to tweak the range to just operate on that data:
>> 2) over the range of that data, do a substitute
>> :%s/^\(\S\+\) .*/xx\1yyy,
>> to put the prefix/suffix/comma in place
making that something like
:5,10s/^\(\S\+\) .*/xx\1yyy,
>> with awk, but I'd like to do it with vim, if it is possible
>> If you want to do it with awk:
>> awk '{printf("%sxx%syyy", NR==1?"":", ", $1)}END{print ""}'
In this case, you'd accrue them all, (re)printing each row as you
process it, then print the joined results at the end
awk '{s = s (sprintf("%sxx%syyy", NR==1?"":", ", $1); print}END{print s}'
-tim