Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-19-2013, 08:39 AM   #1
LQ Newbie
Registered: Feb 2013
Posts: 1

Rep: Reputation: Disabled
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.
Old 02-19-2013, 09:44 AM   #2
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Hi raja219,
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.
Old 02-19-2013, 09:53 AM   #3
Senior Member
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Originally Posted by raja219 View Post
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.
Old 02-20-2013, 01:44 AM   #4
LQ Newbie
Registered: Jan 2013
Distribution: RHEL and AIX ( sort of )
Posts: 18

Rep: Reputation: Disabled
awk or sed - choose your poison.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Split single line into multiple lines with 3 column each udiubu Programming 7 11-26-2017 10:41 AM
sed works on multiple lines but doesn't work on a single line monsteriname Programming 4 10-03-2012 03:23 AM
multiple pattern search in a single file line by line saheervc Linux - Newbie 2 09-02-2010 12:45 AM
how to create a single line of output from multiple variable lines of input steven.c.banks Linux - General 2 02-03-2010 04:09 PM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 03:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration