LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-06-2013, 02:44 AM   #1
fanatic_ravi
LQ Newbie
 
Registered: Jan 2005
Posts: 22

Rep: Reputation: 0
Command to seperate the fields


How should i split the entry below with a single command to filter the contents as below in red colour to the format as below in green colour

Code:
mpath549 (360060e80164f490000014f4900001482) dm-977 HP,OPEN-V
[size=203G]  [features=0]  [hwhandler=0]  [rw]  
\_ round-robin 0 [prio=0]  [active]  
 \_ 3:0:7:49  sdakf 132:880  [failed]  [undef]   
mpath534 (360060e80164f490000014f490000144f) dm-962 HP,OPEN-V
[size=203G]  [features=0]  [hwhandler=0]  [rw]  
\_ round-robin 0 [prio=0]  [active]  
 \_ 3:0:7:34  sdajq 131:896  [failed]  [undef]   
mpath215 (360060e800571ba00000071ba0000a351) dm-406 HP,OPEN-V
[size=101G]  [features=1 queue_if_no_path]  [hwhandler=0]  [rw]  
\_ round-robin 0 [prio=0]  [active]  
 \_ 0:0:3:81  sdqt  132:464  [active]  [undef]   
 \_ 3:0:2:81  sdyt  129:720  [active]  [undef]
Code:
mpath549 360060e80164f490000014f4900001482 size=203G
mpath534 360060e80164f490000014f490000144f size=203G
mpath215 360060e800571ba00000071ba0000a351 size=101G

Last edited by onebuck; 06-06-2013 at 10:44 AM. Reason: clean post by using vbcode tags.
 
Old 06-06-2013, 02:57 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Before we start given (irrelevant?) answers:

- Please put your script/data inside [code] ... [/code] tags to preserve the layout,
- Is this the only entry or are there more entries in a file? If that is the case: Post a relevant portion (at least 2 entries).
 
Old 06-06-2013, 03:10 AM   #3
fanatic_ravi
LQ Newbie
 
Registered: Jan 2005
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Before we start given (irrelevant?) answers:

- Please put your script/data inside [code] ... [/code] tags to preserve the layout,
- Is this the only entry or are there more entries in a file? If that is the case: Post a relevant portion (at least 2 entries).
provided the details now.
 
Old 06-06-2013, 03:18 AM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
I think awk or perl would be the best to use for this.
 
Old 06-06-2013, 03:46 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Have a look at this:
Code:
awk '{ gsub(/[\(\)\[\]]/,"") } /mpath/ { printf"%s %s ",$1,$2 } /size/ { print $1 }' input_file
Example run with above given information:
Code:
$ awk '{ gsub(/[\(\)\[\]]/,"") } /mpath/ { printf"%s %s ",$1,$2 } /size/ { print $1 }' input_file
mpath549 360060e80164f490000014f4900001482 size=203G
mpath534 360060e80164f490000014f490000144f size=203G
mpath215 360060e800571ba00000071ba0000a351 size=101G
 
1 members found this post helpful.
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Separating Fields from Output - cut command Hi_This_is_Dev Linux - General 3 08-28-2010 02:23 PM
[SOLVED] top: select the shown fields from the command-line TITiAN Linux - Software 2 02-08-2010 05:27 PM
[SOLVED] specifying fields for printing in gawk from command line David the H. Programming 8 08-04-2009 03:32 PM
AWK - why fields go to seperate lines? korhan Linux - Newbie 2 03-01-2007 03:21 PM
How to use awk command to parse fields in a line johnsanty Programming 9 05-25-2006 09:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:00 PM.

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