I'm trying to convert a large number of files from a plain text layout to CSV. The first few lines of one of the files looks like this:
SLICE AT X= -0.25
ELEM NO XI-COORD INWARD-NORMAL
1 0 0.000 0.000 0.000 0.000 0.000 0.000
2 0 0.000 0.000 0.000 0.000 0.000 0.000
3 0 0.000 0.000 0.000 0.000 0.000 0.000
The number given in the first line (-0.25) needs to be inserted as a parameter in each of the data rows. Since this number varies in each of the hundreds of files, I can't provide it as a literal.
I've written the following sed program:
# Reduce line 1 to just a number.
s/SLICE AT X= //
# Store line 1 in hold space.
1h
# Clear the other header line.
2d
# Insert X coordinate from hold space.
/^\ \{1,\}/G
# Separate values with commas.
s/\ \{1,\}/,/g
It gets as far as producing this:
-0.25
,1,0,0.000,0.000,0.000,0.000,0.000,0.000
-0.25
,2,0,0.000,0.000,0.000,0.000,0.000,0.000
-0.25
,3,0,0.000,0.000,0.000,0.000,0.000,0.000
-0.25
,4,0,0.000,0.000,0.000,0.000,0.000,0.000
-0.25
Note that the first line of the output is the original first line.
Could anyone help me out getting the pasted number into the start of each line?
Thanks in advance,
Ross