I have a file like:
something1
something2 201101130000
thing
thing1
thing2
AAA, -2, 4, 0, 54;
thing3
thing4
AAA, 43, 43, 0, 5, 0, 0,;
thing5
AAA, 132.0, 43.0, 0.0, 0.0, 43.0,210.0,'
thing5
How to copy the date (201101130000) from the second line, add a comma (,) then put the numbers of the line before last (132,0, 43.0, 0.0, 43.0, 210.0) in newfile.txt
the new file should look like:(the original file does not have spaces between lines as it is here)
20110113, 132.0, 43.0, 0.0, 0.0, 43.0,210.0
I tried grep and sed with no luck. Thanks for your help
Here’s how I’ve interpreted your question:
You’re trying to ‘grep’ and join parts of two lines. These two lines are always the second and second last lines.
You’re also trying to redirect output to another file. You can use shell redirection for this, like:
awk ... file > outputfile.Here’s one way using
sed:Since you’ve tagged this as linux, I’m guessing you’ve got
GNU sedand don’t mind golf:Results:
Explanation:
Alternatively,
awkmay be easier to understand:Results:
Explanation: