LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Break single line into multiple lines based on a pattern (https://www.linuxquestions.org/questions/linux-newbie-8/break-single-line-into-multiple-lines-based-on-a-pattern-4175450786/)

raja219 02-19-2013 07:39 AM

Break single line into multiple lines based on a pattern
 
Hi All,

I have a file with a single line as below.

Processing: [\\servername\filename1] Processing: [\\servername\filename2] Warning: [\\servername\filename3] Processing: [\\servername\filename4] Warning: [\\servername\filename5] Warning: [\\servername\filename6] Processing: [\\servername\filename7] Warning: [\\servername\filename8]

I would like to break this line into multiple lines as below.

Warning: [\\servername\filename3]
Warning: [\\servername\filename5]
Warning: [\\servername\filename6]
Warning: [\\servername\filename8]

Please do the needful by providing the command which gives this result.

RaviTezu 02-19-2013 08:44 AM

Hi raja219,
Quote:

perl -pi -e "s/]/]`echo "\n"`/g" <file_name>
I have taken "]" and replace with "] + new line character".... so if your file doesn't contain any "]" characters in middle. This command works fine.

shivaa 02-19-2013 08:53 AM

Quote:

Originally Posted by raja219 (Post 4895081)
Please do the needful by providing the command which gives this result.

Did you try something yourself? If yes, let's know. IMHO, do not expect a ready-made solution from LQ.

Meanwhile, in addition to perl, awk could do this, if you have ever tried.

smbhandary 02-20-2013 12:44 AM

awk or sed - choose your poison.


All times are GMT -5. The time now is 07:33 PM.