sed - loop construct for text processing
I'm learning the sed loop construct and having difficulty.
The input file consists of a variable number of blank-delimited fields. Sample input file: Code:
000001 now is the time with whatever appears in the first field. In this example the first field is a line number but it could be anything (color, city, car model, etc.) Sample output file: Code:
000001 000001 000001 000001 000001 If so, please show how it is done. Daniel B. Martin |
Hi,
Not sure if I would use sed to do this, awk comes to mind: Code:
awk '{ for ( z = 1; z <= NF; z++ ) printf("%s ",$1) }{ print "" } ' infile Hope this helps. |
Hi again.
Here is a commented sed solution, I'm relatively satisfied with (put it to file and make executable) Code:
#!/bin/sed -rf Code:
sed -r 's/$/ =/; h; s/ .*$//;x; s/ +/\n/g; :a; s/[^\n]*\n//; G; /^=/be; ba; :e; s/\n/ /g; s/= //' |
Hi,
you could try this: Code:
sed -r ':a;s/([0-9]+) [a-zA-Z]+(.*)/\1 \1\2/g;ta' Code:
000001 now is the 3rd time |
Quote:
Daniel B. Martin |
[QUOTE=crts;4583633]
Code:
sed -r ':a;s/([0-9]+) [a-zA-Z]+(.*)/\1 \1\2/g;ta' Daniel B. Martin |
All times are GMT -5. The time now is 08:39 AM. |