regex - Format a file based on the IFS -
i using sed
concatenate contents of file as:
cat source.c | sed -e :a -e '$!n; s/\n/ /; ta'
the file contains relevant informations [ series of strings ] separated pipe |
. want change ifs
pipe |
and output may piping new ifs
thereby displaying new formatted file stdout.
an instance of source.c after concatenation :
void f0 (***) | void f1 (***) | void f2 (***)| void f3 (***)
what hope achieve setting ifs
:
void f0 (***) void f1 (***) void f2 (***) void f3 (***)
thanks in advance replies .i not sure if possible files , , dont want involve variables or arrays here .
edit : source file appears in beginning :
void f0 (***) | void f1 (***) | void f2 (***) | void f3 (***)
so first concatenate double space each word group , split using pipe delimiter .
sed -e :a -e '$!n; s/\n/ /; ta' source.c | sed -e 's/ */ /g' -e 's/ *//'
the sed
, awk
alternative job .
answer selected based on upvotes @ time of first edit :) . suggested in 1 of answers leaving question unchanged in order others find these uncomplicated alternatives instead of messing ifs
.
if that's want, replace '|' newlines.
echo 'void f0 (***) | void f1 (***) | void f2 (***)| void f3 (***) ' | sed 's, *| *,\n,g'
or command:
sed -e :a -e '$!n; s/\n/ /; ta' source.c | sed 's, *| *,\n,g'
messing shell's ifs can obscure problems. messing awk's not problem though:
echo 'void f0 (***) | void f1 (***) | void f2 (***)| void f3 (***) ' | awk 'begin {rs="|";} { print $0}' sed -e :a -e '$!n; s/\n/ /; ta' source.c | awk 'begin {rs="|";} { print $0}'
Comments
Post a Comment