I am looking for away contact lines based on the next line. So far the only way I see is to create a shell script that will read line by line and will do something along these lines:
while read line
if $line does not start with "," and $curr_line is empty
store line in curr_line
if $line does not start with "," and $curr_line is not empty
flush $curr_line to file
store $line in $curr_line
if $line starts with "," append to $curr_file, flush to file empty curr_line
done < file
So I am trying to understand if could be achieved with sed or even grep with redirection. the rules of the file are simple. There is at max one and only one line starting with "," that needs to be appended to the previous line.
ex:
line0
line1
line2
,line3
line4
line5
,line6
line7
,line8
line9
line10
line11
The result file would be
line0
line1
line2,line3
line4
line5,line6
line7,line8
line9
line10
line11
awk '/,/||NR==1{printf $0; next}{printf "\n"$0}' < file
? – Valentin B. Nov 15 '16 at 15:40/^,/
andprintf "%s", $0
. – Stéphane Chazelas Nov 15 '16 at 15:48printf $0
seems to work though without adopting the formating, don't know if it's "supposed" to. – Valentin B. Nov 15 '16 at 15:52%
characters. – Stéphane Chazelas Nov 15 '16 at 16:02printf
shell builtin btw, you should really get used to never use external data as the format. – Stéphane Chazelas Nov 15 '16 at 16:19