Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting data from one line 1

Status
Not open for further replies.

rella

Technical User
Feb 10, 2005
3
US
My input looks like this:

[Name1] = { [Level] = 18, [Class] = Class1, [Rank] = Member1, },
[Name2] = { [Level] = 17, [Class] = Class2, [Rank] = Member2, },
[Name3] = { [Level] = 16, [Class] = Class3, [Rank] = Member3, },
[Name4] = { [Level] = 15, [Class] = Class4, [Rank] = Member4, },


What I’d like to see output is this:


Name1 18 Class1 Member1
etc....

Any help you can give me is greatly appreciated, even if just pointing me in the right direction. I tried using the = as a field separator but that doesn't help me get the name. I hate being a novice.

:)
 
You may try this:
nawk '
{gsub(/[\[\]{},=]/,"");gsub(/(Level|Class|Rank)/,"");print}
' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
elaborating a bit on PHV posting:

Code:
{
  gsub(/[\[](Level|Class|Rank)[\]]/,"")
  gsub(/[\[\]{},=]/,"")
  print
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Code:
BEGIN { FS = " = |, " }
{ gsub( /\[|\]/, "" )
  printf "%-12s%-7s%-10s%s\n", $1,$3,$5,$7
}
Let me know whether or not this helps.

If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. Under Solaris, use /usr/xpg4/bin/awk.

For an introduction to Awk, see faq271-5564.

PHV, remember what I told your about testing your code?
 
Futurelet,


That worked perfectly.. thanks!

Now I'm going to figure out why it worked :)

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top