LinuxQuestions.org
Visit Jeremy's Blog.
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-12-2013, 03:55 AM   #1
fanatic_ravi
LQ Newbie
 
Registered: Jan 2005
Posts: 22

Rep: Reputation: 0
Parse a file


Any command to read a file with entries as below

mpath0 3600601602b702d006218b7de8100e111
mpath1 3600601602b702d0089a6a26c3f31e111
mpath2 3600601602b702d0088a6a26c3f31e111
mpath3 3600508b1001cab8358dfaef03cf53284


and display o/p as below . the Last 6 digits should be considered and should be in CAPs

mpath0 00:E1:11
mpath1 31:E1:11
mpath2 31:E1:11
mpath3 F5:32:84

Last edited by fanatic_ravi; 06-12-2013 at 03:56 AM.
 
Old 06-12-2013, 04:29 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Have a look at this:
Code:
sed -r 's/(.*) .*(..)(..)(..)/\1 \2:\3:\4/' input
Example run with given example:
Code:
$ sed -r 's/(.*) .*(..)(..)(..)/\1 \2:\3:\4/' input 
mpath0 00:e1:11
mpath1 31:e1:11
mpath2 31:e1:11
mpath3 f5:32:84
EDIT: Above solution doesn't implement the CAPS part, see next post.

Last edited by druuna; 06-12-2013 at 04:52 AM.
 
Old 06-12-2013, 04:52 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Oops.... Missed the CAP's part, here's one that should do the trick:
Code:
 sed -r 's/(.*) .*(..)(..)(..)/\1 \U\2:\3:\4/' input
Example run:
Code:
$ sed -r 's/(.*) .*(..)(..)(..)/\1 \U\2:\3:\4/' input 
mpath0 00:E1:11
mpath1 31:E1:11
mpath2 31:E1:11
mpath3 F5:32:84
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse a CSV file output to text file beto Linux - Newbie 3 04-25-2012 08:45 AM
[SOLVED] Parse/rewrite file help Linux_Kidd Programming 15 11-07-2011 07:17 AM
[SOLVED] Best way to Parse a file Stuart07 Programming 6 05-05-2011 07:56 AM
Parse file from remote server to caculate count of string existence in that file saurabhmehan Linux - Newbie 2 08-30-2010 12:30 AM
a script to parse a file SamuelHenderson Programming 5 03-15-2007 03:23 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration