Multi line document to single lines based on occurance of string

Hi Guys,

I am new to awk and sed, i am working multiline document, i want to make make that document into SINGLE lines based on occurace of string "dwh".

here's the sample of my problem..

dwh123 2563 4562 4236 1236 78956 12394 4552 dwh192 2656 46536 231326 65652 6565 23262 16625623 dwh956 2365 12232 46656 56522 464646 66262 65522...so..on

desided out put is..

dwh123 2563 4562 4236 1236 78956 12394 4552
dwh192 2656 46536 231326 65652 6565 23262 16625623
dwh956 2365 12232 46656 56522 464646 66262 65522

I really appertiate your help.

Thanks!

$ echo $samplet
dwh123 2563 4562 4236 1236 78956 12394 4552 dwh192 2656 46536 231326 65652 6565 23262 16625623 dwh956 2365 12232 46656 56522 464646 66262 65522

$ echo $samplet | sed 's/dwh/~dwh/g' | tr "~" "\n"

dwh123 2563 4562 4236 1236 78956 12394 4552
dwh192 2656 46536 231326 65652 6565 23262 16625623
dwh956 2365 12232 46656 56522 464646 66262 65522
1 Like

Thanks Joey. It worked great

sed 's/\(.\)dwh/\1\
dwh/g' inputFile

To avoid having 1st line as new line.

If the records are always by 8 columns. Here is a simple command.

xargs -n8 < infile

or by awk:

awk '{gsub(/dwh/,"\ndwh")}1' infile
 ruby -pne 'gsub(/dwh/,"\ndwh")' file