A challenge for you sed/awk wizards...

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers A challenge for you sed/awk wizards...
# 1  
Old 10-24-2007
A challenge for you sed/awk wizards...

Here's a challenge for you wizards...

I have a file formatted as follows;

$[{"_q":"Bobby","_feild1":"id3","_feild2":"users","_feild3":"3bc44332a28a7","feild4":"Bobby","feild5":8,"feild6":50},{"html":1,"type":"msgitem_mini","name":"Found <span class='b'>8<\/span> results."},{"id":"87654321,12345678,09876543","ids":3,"type":"item","name":"Bobby - One"},{"id":"1107338","ids":1,"type":"item","name":"Bobby! - Two"},{"type":"msgitem","style":"HRitem"}]

What I need to output is;

87654321 Bobby One
12345678 Bobby One
09876543 Bobby One
1107338 Bobby! Two

Any Ideas how I can do this? I've tried sed but I'm not sure if perl might be a better way to go and I'm not too familiar with that.

Any help would be greatly appreciated!!


# 2  
Old 10-24-2007
awk '/"id"/{split($2,n,",");for(i in n)print n[i],$6}' RS="}" FS='"[:,]"|"$' filename

Use nawk or /usr/xpg4/bin/awk on Solaris.

If the order is important Smilie

awk '/"id"/{c=split($2,n,",");for(i=1;i<=c;i++)print n[i],$6}' RS="}" FS='"[:,]"|"$' filename

# 3  
Old 10-24-2007
You're a star! Wow... Thanks!

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Anyone like a challenge?

I have searched through google, and this forum to try and find the answer, but alas, nothing quite hits the whole answer. I am trying to read the last line (or lines) of some log files. I do this often. The files are named sequentially, using the date as part of the file name, and appending... (18 Replies)
Discussion started by: BatterBits
18 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. UNIX for Advanced & Expert Users

Interesting awk/Perl/sed parsing challenge

I have a log with entries like: out/target/product/imx53_smd/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/bindings/V8HTMLVideoElement.cpp : target thumb C++: libwebcore <=... (8 Replies)
Discussion started by: glev2005
8 Replies

4. What is on Your Mind?

Of Computer wizards and games

You guys are really are a genius, you make computer processing more easy for us end users. You just don't make wonders but you also make good computer games too. Really there is a fast evolution on the era of the computer world. Thanks to you guys! __________________ The Cute Angry Birds... (0 Replies)
Discussion started by: methusela123
0 Replies

5. Shell Programming and Scripting

regex challenge

Here's a regex substitution operation that has stumped me with sed: How do you convert lines like this: first.key ?{x.y.z} second.key ?{xa.ys.zz.s} third.key ?{xa.k} to: first.key ?{x_y_z} second.key ?{xa_ys_zz_s} third.key ?{xa_k} So i'm basically converting all the... (11 Replies)
Discussion started by: neked
11 Replies

6. Shell Programming and Scripting

sed xml challenge

I have a web xml file that looks like this: <allinfo> <info> <a>Name1<\a> <b>address1<\b> <c>phone1<c> <\info> <info> <a>Name2<\a> <b>address2<\b> <c>phone2<c> <\info> <\allinfo> I want to use sed to... (2 Replies)
Discussion started by: katrvu
2 Replies

7. Shell Programming and Scripting

sed replacement, challenge one!!!!

Hi all, Thanks in advanced. This question really bothered me much. What i want is to replace any times of repeated 'TB' to 'T', below is example. It can be fullfil by AWK and perl, but my desire is using SED to realize it. So here means we treat TB as a whole part, which means 's/TB*/T/'... (4 Replies)
Discussion started by: summer_cherry
4 Replies

8. Shell Programming and Scripting

AWK Challenge

I have the following text Microsoft iSCSI Initiator version 2.0 Build 3497 Targets List: iqn.2001-05.com.equallogic:0-8a0906-daef43402-138000002a4477ba-grsrv12-extra iqn.2001-05.com.equallogic:0-8a0906-986f43402-520000002b447951-exchange ... (9 Replies)
Discussion started by: netmedic
9 Replies

9. UNIX for Advanced & Expert Users

safeword challenge

Hi, there are some servers here at work which issue a Safeword challenge after I login. Can anyone tell me exactly how the challenge/response system works? In particular, how are the valid keys decided? (2 Replies)
Discussion started by: blowtorch
2 Replies
Login or Register to Ask a Question

Featured Tech Videos