Wednesday, October 5, 2022

[SOLVED] Removing new line after a particular text via bash/awk/sed/perl

Issue

I would like to remove all the newline character that occurs after a partiular string and replace it with a tab space. Say for instance my sample.txt is as follows

foo
bar bar bar bar some text

I would like it to be

foo    bar bar bar bar some text

How do I do this via bash/awk/sed. Do help.


Solution

In awk:

awk '/foo$/ { printf("%s\t", $0); next } 1'


Answered By - Michael J. Barber
Answer Checked By - Cary Denson (WPSolving Admin)