LinuxQuestions.org
Review your favorite Linux distribution.
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 12-17-2014, 09:58 AM   #1
LinuxNoob339
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Rep: Reputation: Disabled
text editing using bash scritping


I would like to sort the output of multipath -ll into a csv type of file using bash script. For example # multipath -ll would give the following output


360060e80056fc30000006fc30000513c dm-41 HITACHI,OPEN-V
\_ 4:0:0:45 sdcm 69:160 [active][ready]
\_ 3:0:0:45 sdcn 69:176 [active][ready]
360060e80056fc30000006fc300005162 dm-31 HITACHI,OPEN-V
\_ 3:0:0:36 sdbu 68:128 [active][ready]
\_ 4:0:0:36 sdbv 68:144 [active][ready]
360060e80056fc30000006fc300005127 dm-56 HITACHI,OPEN-V
\_ 3:0:0:6 sdg 8:96 [active][ready]
\_ 4:0:0:6 sdt 65:48 [active][ready]

What I would like is to create a csv file that would be in this format
LUN ID no., SCSI DEVICE1, SCSI DeVICE2
360060e80056fc30000006fc300005127,sdg,sdt
360060e80056fc30000006fc300005162,sdbu,sdbv

I am just looking for a basic idea of how it could be done, not the entire script. Any help would be greatly appreciated.
 
Old 12-17-2014, 10:47 AM   #2
r0tty
Member
 
Registered: May 2011
Posts: 33

Rep: Reputation: 1
Hi,

How about something like this:

multipath -ll | paste - - - | cut -d " " -f 1,3,5

You'd need to pick the fields you want yourself. If you don't want a full field you may need to use another command to refine it a bit.

The big problem with this approach is that it will fail if you have anything other than three lines per device.

If that is a problem you could do something like this:

multipath -ll | awk '
/^3600/ { print $0 }
/^\\/ { print $3 " " $4}'

Hope that helps.

Regards,
Rotty
 
Old 12-26-2014, 10:29 AM   #3
LinuxNoob339
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks.
 
  


Reply


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
[SOLVED] Bash command to 'cut' text into another text file & modifying text. velgasius Programming 4 10-17-2011 05:55 AM
Text editing: Adding a digit/text to the end of a row CHARL0TTE Linux - Newbie 13 07-16-2009 07:44 AM
Bash scritping help investmentbnker75 Programming 7 09-29-2008 10:31 PM
Scritping - Point in the right direction eltnux Linux - Newbie 5 01-30-2008 03:00 PM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 12:55 PM


All times are GMT -5. The time now is 06:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration