It is currently Sat May 26, 2018 5:34 pm

Use Sed Awk to Parse Text File

All times are UTC - 6 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Wed Feb 12, 2014 9:46 am   

Joined: Wed Feb 12, 2014 9:30 am
Posts: 1

I am having a problem trying to get started with Sed and Awk which I believe is the best solution to my current problem.

I have a text file which repeats this:

Not a real host            ##<--- if Not a real host ignore all lines until next blank line
uuid (MI)
                : 239043289-3249329-239408932-48329403
           uid: 239490329-9504835-943509348-39858439
        name: test1
        vmst:  data
          net:  data

uuid (MI)                   ##<---- Is a real host so parse the number directly below and parse the name field and move on
              : 320-9493493-3904239-3940392-4239408329492
         uid: 3040320-23-3294023890234-329482390-239483
      name: test2
      vmst: data
        net: data


I am simply trying to read line by line, if its a real host parse the first number and name and move on to next block

correct output:

So far I am thinking I will search for text "Not a real host", then delete all lines until next empty line and do this for the entire file.

Then I will read entire file again and search for string "uuid (MI)" and just parse out the next line below for the number and then the 3 line below that for the name.

Perhaps someone out there can provide me feedback or a better way to do this?

Thanks in advance,


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group