2
cat > inputfile

X1 a1,b1,c1,d1.................. dn
X2 a2,b2,c2,d2.................. and so on upto n
................................................
................................................
Xn an,bn,cn,dn....................and so on upto n

output format:

X1 a1 +
   b1 +
   c1 +
   .
   .
   .
   .

X2 a2 +
   b2 +
   c2 +
   .
   .
   .


and so on

I am trying something like

 sed ':b;s/,/\
/;tb;s/\
/ +/g'

NOTE : I need to add a tab before b1 +,c1 +.... ,b2 +,c2 +,... etc

4

Given this inputfile:

X1 a1,b1,c1,d1
X2 a2,b2,c2,d2
X3 a3,b3,c3,d3
X4 a4,b4,c4,d4

With sed (using bash ANSI-C quoting for clarity):

sed $'s/,/ +\\\n\t/g' inputfile
X1 a1 +
    b1 +
    c1 +
    d1
X2 a2 +
    b2 +
    c2 +
    d2
X3 a3 +
    b3 +
    c3 +
    d3
X4 a4 +
    b4 +
    c4 +
    d4

sed needs to see a backslash before the newline, otherwise you get an "unterminated s command" error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.