2018.07.01, Sunday
09:27 some text 123456789 0 21 0.06 0.07 0.00
2018.07.02, Monday
09:31 some text 123456789 1 41 0.26 0.32 0.00
09:39 some text 456789012 1 0.07 0.09 0.09
09:45 some text 932469494 1 55 0.29 0.36 0.00
16:49 some text 123456789 0 48 0.12 0.15 0.00
20:13 some text 123456789 0 46 0.12 0.15 0.00
I want the sed command to find the pattern YYYY.MM.DD, Day of week (Y-year, M-month, D-Day, e.g. 2018.07.01, Sunday) and:
to copy the pattern to the buffer
to remove the pattern from the given line and then
to past the pattern into the line below so that you get the effect below
2018.07.01, Sunday 9:27 am some text 123456789 0 21 0.06 0.07 0.00
2018.07.02, Monday 9:31 some text 123456789 1 41 0.26 0.32 0.00
2018.07.02, Monday 09:39 some text 456789012 1 0.07 0.09 0.09
2018.07.02, Monday 9:45 some text 932469494 1 55 0,29 0,36 0,00
2018.07.02, Monday 16:49 some text 123456789 0 48 0.12 0.15 0.00
2018.07.02, Monday 20:13 some text 123456789 0 46 0.12 0.15 0.00
Any attempts / ideas / thoughts from your side? Where does the "am" in the first output line come from?
Similar problems have been solved umpteen times in here - did you try searching?
Would be an easy thig to do with awk ; but as you insist on sed , try
sed -rn '/[0-9]{4}(\.[0-9]{2}){2}, [[:alpha:]]+/ {h;n;}; H; x; s/\n/\t/; p; G; s/\n/\t/; s/(.*)(\t.*)\2/\1/; x; ' file
2018.07.01, Sunday 09:27 some text 123456789 0 21 0.06 0.07 0.00
2018.07.02, Monday 09:31 some text 123456789 1 41 0.26 0.32 0.00
2018.07.02, Monday 09:39 some text 456789012 1 0.07 0.09 0.09
2018.07.02, Monday 09:45 some text 932469494 1 55 0.29 0.36 0.00
2018.07.02, Monday 16:49 some text 123456789 0 48 0.12 0.15 0.00
2018.07.02, Monday 20:13 some text 123456789 0 46 0.12 0.15 0.00
Inserting a <TAB> in lieu of a space is necessary to identify the line added; not sure how to simplify. There may be more elegant solutions to come, however...
[quote=rudic;303021898]
Would be an easy thig to do with awk ; but as you insist on sed , try
sed -rn '/[0-9]{4}(\.[0-9]{2}){2}, [[:alpha:]]+/ {h;n;}; H; x; s/\n/\t/; p; G; s/\n/\t/; s/(.*)(\t.*)\2/\1/; x; ' file
Thanks a lot RudiC :b:
I have more sed commands to execute as below.
s/^$/d/
/^[a-zA-Z]/d
I want to use
sed -f script-file
but if I add your sed it does not work. Could your advice how I can putt all sed into script-file?
2018.07.01, Sunday
09:27 some text 123456789 0 21 0.06 0.07 0.00
2018.07.02, Monday
09:31 some text 123456789 1 41 0.26 0.32 0.00
09:39 some text 456789012 1 0.07 0.09 0.09
09:45 some text 932469494 1 55 0.29 0.36 0.00
16:49 some text 123456789 0 48 0.12 0.15 0.00
20:13 some text 123456789 0 46 0.12 0.15 0.00