LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-19-2013, 07:39 AM   #1
raja219
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, 08:44 AM   #2
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
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.
 
Old 02-19-2013, 08:53 AM   #3
shivaa
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
Quote:
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, 12:44 AM   #4
smbhandary
LQ Newbie
 
Registered: Jan 2013
Distribution: RHEL and AIX ( sort of )
Posts: 18

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


Reply



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 09:41 AM
sed works on multiple lines but doesn't work on a single line monsteriname Programming 4 10-03-2012 02:23 AM
multiple pattern search in a single file line by line saheervc Linux - Newbie 2 09-01-2010 11:45 PM
how to create a single line of output from multiple variable lines of input steven.c.banks Linux - General 2 02-03-2010 03:09 PM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 02:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:14 AM.

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