Shreya
Shreya

Reputation: 649

Print text of line in two different lines

My input is as

Type combinational  function (A B)

Want output to be

Type combinational 
function (A B)

I used code

sed "/'^Type '/a 'function '" input 

But using this I am getting function word in next line after Type. Where I am wrong.

Upvotes: 1

Views: 54

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133780

With shown samples could you please try following.

sed 's/\([^ ]* [^ ]*\) \(function.*\)/\1\n\2/' Input_file

Explanation: using back reference capability of sed, where I am creating 2 captured groups, 1st group stores values till the 2nd spaces comes into it. 2nd back reference stores values after 2nd space occurs. Then while performing substitution, using \1 to get values inside 1st back reference and using \2 2nd backreference for getting 2nd stored value, Putting \n to get a new line between matched values as per question.

Upvotes: 2

Related Questions