Hello
I have an input as below
[2014-03-03t23:15:45] this is test
[2013-14-20t12:23:12]we
are(
)
[
]
one
[2012-03-03t23:15:45] end of description
I am looking for output
[2014-03-03t23:15:45] this is test
[2013-14-20t12:23:12]we are ()[] one
[2012-03-03t23:15:45] end of description
To get output like that, you're going to have to provide a detailed description describing when spaces are to be added to text in an existing line, and when spaces are to be added before or after text when lines are joined.
What have you tried?
awk 'NR == 1 {p = $0; next}
{if($0 ~ /^\[[12][0-9][0-9][0-9]-.+\]/) {print p; p = $0}
else {p = (p $0)}}
END {print p}' file
Output:
[2014-03-03t23:15:45] this is test
[2013-14-20t12:23:12]weare()[]one
[2012-03-03t23:15:45] end of description
awk 'NR == 1 {p = $0; next}
{if($0 ~ /^\[[12][0-9][0-9][0-9]-.+\]/) {print p; p = $0}
else {p = (p " " $0)}}
END {print p}' file
Output:
[2014-03-03t23:15:45] this is test
[2013-14-20t12:23:12]we are( ) [ ] one
[2012-03-03t23:15:45] end of description