Parse (delimited string) key-value pairs in a column into separate lines


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Parse (delimited string) key-value pairs in a column into separate lines
# 1  
Old 11-25-2012
Parse (delimited string) key-value pairs in a column into separate lines

Hi experts,

e.g.

i/p data looks like

Code:
0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified||

o/p data should like -
Code:
row1: 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747|unidentified

row2:0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405717924|unidentified

row3:0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405733788|unidentified

I want to do it at the file level instead of in database. Any help will be greatly appreciated.

Thanks.
Suyog.

Last edited by Scott; 11-25-2012 at 06:03 PM.. Reason: Code tags
# 2  
Old 11-25-2012
Why do you post the same problem twice? This is very irritating!

Try like:
Code:
$ awk 'BEGIN{FS=OFS="|"}; {n=split($3, A, ","); split($4, B, ","); for (i=1;i<=n; i++) print $1,$2,A[i],B[i]}' file
0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747|unidentified
0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405717924|unidentified
0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405733788|unidentified


Last edited by RudiC; 11-25-2012 at 07:13 PM.. Reason: Expressed my irritation about posting twice
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to parse parts of 1 column into two separate columns?

I have a shell script that is currently transferring a csv file from a server into a Teradata database table. One of the 30 or so columns is called "destination_url". In that URL there are parameters, and it is possible for those parameters to be repeated because of referring companies copying... (3 Replies)
Discussion started by: craigwg
3 Replies

2. Shell Programming and Scripting

Replace pipe delimited column string to null

Hi All, I have a large dat file where each lines are pipe delimited values. I need to parse the file depending on the request. For example: sometimes I have told to remove all the values in the 7th column (this case remove values '3333' only from the first line and '3543' from the second line)... (4 Replies)
Discussion started by: express14
4 Replies

3. Shell Programming and Scripting

Extracting key/value pairs in awk

I am extracting a number of key/value pairs in awk using following: awk ' /xyz_session_id/ { n=index($0,"xyz_session_id"); id=substr($0,n+15,25); a=$4; } END{ for (ix in a) { print a } }' I don't like this Index + substr with manually calculated... (5 Replies)
Discussion started by: migurus
5 Replies

4. UNIX for Advanced & Expert Users

Parse key-value pair into separate rows

Hi, I'm getting key-value pairs in a string as follows - 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified I need output as follows - row1:... (5 Replies)
Discussion started by: sumoka
5 Replies

5. Shell Programming and Scripting

Create new lines using a delimited string.

Hi I have a text file called 'fileA' which contains the follwoing line examples 01:rec1:25,50,75,100 02:rec2:30,60 03:rec3:20,40 I would like to create a new file where each of the comma separated values appears on a new line but prefixed with the first two fields e.g. 01:rec1:25... (3 Replies)
Discussion started by: mackmb
3 Replies

6. UNIX for Dummies Questions & Answers

how to print the column that contains a string in delimited file in unix

Hi Team, I have a requirement to print the column or find the column number of a particular string in delimited (;) file. Ex: aaa;bbb;ccc;rrr;mmm; gggg;rrr;mmmm;ssss;eee;aaa; ccc;gggg;tttt;bbbb;dddd;ggggg;rrr; my file contains 1000+ rows like above example with semicolon... (3 Replies)
Discussion started by: baskivs
3 Replies

7. Shell Programming and Scripting

Separate lines in csv by column content (newbie)

Hello everyone I have a csv file organized just like in the following example: col1,col2,col3,CODE_0, ... , colN col1,col2,col3,CODE_0, ... , colN col1,col2,col3,CODE_1, ... , colN col1,col2,col3,CODE_1, ... , colN col1,col2,col3,CODE_1, ... , colN col1,col2,col3,CODE_2, ... , colN... (7 Replies)
Discussion started by: yomaya
7 Replies

8. Shell Programming and Scripting

Use awk or sed to parse delimited string

Hi I am trying to figure out the best way to search a long log file and print out certain information. For example if I had a line in a log file delimited by ampersand first_name=mike&last_name=smith&zip_code=55555&phone=555-5555&state=ma&city=boston and I only wanted to search for and... (3 Replies)
Discussion started by: mstefaniak
3 Replies

9. Shell Programming and Scripting

Searching a delimited Key value pairs in shell script

Hello, I have property file with key value pairs separated by pipe , I am trying to write a script which reads the property file and search and print value of specific key. I tried with Sed, I am successfull. The file is as follows ... (4 Replies)
Discussion started by: ANK
4 Replies

10. UNIX for Dummies Questions & Answers

Search and replace string only in a particular column in a delimited file

I have file with multiple columns. Column values for a record may be same. Now i have to replace a column value(this can be same for the other columns) with new value. File.txt A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D A,B,C,D,A,B,C,D,A,B,C,D... (1 Reply)
Discussion started by: ksailesh
1 Replies
Login or Register to Ask a Question