Вы можете использовать sed
для объединения следующей строки с текущей, если текущая строка не содержит 4 |
символов:
<file sed -e :1 -e 's/|/|/4;t' -e 'N;s/\n/ /;b1'
В некоторых реализациях sed
есть -i
или -i ''
для редактирования файлов в -место(-i.back
для сохранения оригинала с расширением .back
), так что с ними вы можете сделать:
sed -i -e :1 -e 's/|/|/4;t' -e 'N;s/\n/ /;b1'./*.csv
Для редактирования всех не -скрытых csv
файлов в текущем каталоге.
То же с комментариями:
<file sed '
:1
s/|/|/4; # replace the 4th | with itself. Only useful when combined with
# the next "t" command which branches off if the previous
# substitution was successful
t
# we only reach this point if "t" above did not branch off, that is
# if the pattern space does not contain 4 "|"s
N; # append the next line to the pattern space
s/\n/ /; # replace the newline with a space
# and then loop again in case the pattern space still does not contain
# 4 "|"s:
b1'