Put raw data to column data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put raw data to column data
# 1  
Old 03-19-2007
Put raw data to column data

Dear all,

I want below data to make it in column format.so i will see the data like this

cdrID teleServiceCode chargedPartyNumber ... ... ... ...
"egmailcom0w10ggzx00" 'sMS (5)' "716323770"
"m17ifi5z30w0z6o7200" 'sMS (5)' "716073407"


SDPINPUTCDR.SDPCallDetailRecord.chargeEventCDR
{
cdrID : "egmailcom0w10ggzx00"
teleServiceCode : 'sMS (5)'
chargedPartyNumber : "716323770"
otherPartyNumber : "een@gmail.com"
time : "084127"
date : "20070319"
duration : "0"
extensionInt1 : '4'D
}
bash-2.05$ more F200703190235_1190
SDPINPUTCDR.SDPCallDetailRecord.chargeEventCDR
{
cdrID : "m17ifi5z30w0z6o7200"
teleServiceCode : 'sMS (5)'
chargedPartyNumber : "716073407"
otherPartyNumber : "724670778"
time : "080532"
date : "20070319"
duration : "7"
extensionInt1 : '5'D
}


pls help me to do this.

Thanks,
Nayanajith.
# 2  
Old 03-19-2007
Hi,
Try to use this awk script.....
BEGIN{
lnLine=0;
RecdCount=0;
}
{
if($0 ~ /^SDPINPUTCDR/)
{
getline;
getline;
while(1)
{
split($0,temp,":");
Hdr[temp[1]]=1;
Val[temp[1] "," RecdCount]=temp[2];
if($0 ~ "}")
{
break;
}
getline;
}
RecdCount++;
}
}
END{
for(i in Hdr)
{
printf("%s ",i);
}
printf("\n");


for(j=0;j<RecdCount;j++)
{
for(i in Hdr)
{
printf("%s ",Val[i "," j]);
}
printf("\n");
}
}
Thanks
Raghuram
# 3  
Old 03-19-2007
Code:
awk '{ if( NR == 1 ) { for ( i=1; i<=NF; i++ ) { arr[i] = $i; } } else { for( i=1; i<=NF; i++ ) { printf "%s : %s\n", arr[i], $i } } }' filename

# 4  
Old 03-19-2007
if you have Python, here's an alternative:
Code:
#!/usr/bin/python
f = open("file")
f.readline()
headers=[]
values=[]
for i in f.readlines():
        if "{" in i or "}" in i: continue
        a,b = i.split(" : ")
        headers.append(a)
        values.append(b.strip())
for i in headers:
        print "%-10s" %i,
for j in values:
        print "%-10s" % j,

# 5  
Old 03-20-2007
Quote:
Originally Posted by matrixmadhan
Code:
awk '{ if( NR == 1 ) { for ( i=1; i<=NF; i++ ) { arr[i] = $i; } } else { for( i=1; i<=NF; i++ ) { printf "%s : %s\n", arr[i], $i } } }' filename


it is not working as i want.Below is the data file.

SDPINPUTCDR.SDPCallDetailRecord.chargeEventCDR
{
cdrID : "egmailcom0w10ggzx00"
teleServiceCode : 'sMS (5)'
chargedPartyNumber : "716323770"
otherPartyNumber : "een@gmail.com"
time : "084127"
date : "20070319"
duration : "0"
extensionInt1 : '4'D
}
bash-2.05$ more F200703190235_1190
SDPINPUTCDR.SDPCallDetailRecord.chargeEventCDR
{
cdrID : "m17ifi5z30w0z6o7200"
teleServiceCode : 'sMS (5)'
chargedPartyNumber : "716073407"
otherPartyNumber : " "
time : "080532"
date : "20070319"
duration : "7"
extensionInt1 : '5'D


i want make this data in columns as below.



m17ifi5z30w0z6o7200 'sMS (5)' 716073407 724670778 ....
.... ..... ...... ...... ....


Hope u get my point.

Thanks,
Nayanajith.
# 6  
Old 03-20-2007
Code:
$ awk -v RS="}" -v FS="\n" ' { for ( i = 1; i <= NF ; ++i ) if ( $i ~ /:/ ) { sub(".*: *","",$i);
> printf("%s ",$i) } printf("\n") } ' file
"egmailcom0w10ggzx00" 'sMS(5)' "716323770" "een@gmail.com" "084127" "20070319" "0" '4'D
m17ifi5z30w0z6o7200 'sMS (5)' 716073407 724670778 080532 20070319 7 '5'D

# 7  
Old 03-20-2007
Plz try this...

sed -e '/{/,/}/!d' -e '/[{}]/d' filename| awk -F":" ' BEGIN {printf "\n\ncdrID teleServiceCode chargedPartyNumber otherPartyNumber time date duration\n"}{ if(NR%8 == 0) print "\n"; else printf $2" "; }'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change data in one column with data from another file's column

Hello, I have this file outputData: # cat /tmp/outputData __Capacity^6^NBSC01_Licences^L3_functionality_for_ESB_switch __Capacity^2100^NBSC01_Licences^Gb_over_IP __Capacity^1837^NBSC01_Licences^EDGE_BSS_Fnc __Capacity^1816^NBSC01_Licences^GPRS_CS3_and_CS4... (1 Reply)
Discussion started by: nypreH
1 Replies

2. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

3. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

4. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

5. Shell Programming and Scripting

Replace data of one column with data on other file corresponding to transaction ID matched

Hi All, I have two files one of which having some mobile numbers and corresponding value whose sample content as follows: 9058629605,8.0 9122828964,30.0 And in second file complete details of all mobile numbers and sample content as follows and delimeter used is comma(,): ... (8 Replies)
Discussion started by: poweroflinux
8 Replies

6. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

7. Shell Programming and Scripting

Linear data to column data..script help seeked

Hello Take a look at following lines. This is giving me an o/p all in one array where as i want the column to be printed.How can i do it? e.g I am getting: 1575028616...... whereas i want 1 5750 28616 I am writing this small piece and trying to get this column o/p in a CSV. ... (1 Reply)
Discussion started by: ak835
1 Replies

8. Shell Programming and Scripting

raw data to column data

I have a data file like this. SDPINPUTCDR.SDPCallDetailRecord.chargeEventCDR { cdrID : "egmailcom0w10ggzx00" teleServiceCode : 'sMS (5)' chargedPartyNumber : "716323770" otherPartyNumber : "een@gmail.com" time : "084127" date : "20070319" duration : "0" extensionInt1 : '4'D }... (3 Replies)
Discussion started by: Nayanajith
3 Replies

9. Shell Programming and Scripting

How to change Raw data to Coloumn data fields

Dear All, I have some data file.see below. --------------ALARM CLEARING FROM SubNetwork=ONRM_RootMo,SubNetwork=AXE,ManagedElement=CGSN-------------- Alarm Record ID: 25196304 Event Time: 2006-08-28 13:41:35 Event Type: ... (1 Reply)
Discussion started by: Nayanajith
1 Replies

10. UNIX for Advanced & Expert Users

copying data to raw devices using 'dd'

Hello all, I'm new here, so this information may exist elsewhere on this forum. If so, please point me in the right direction. Here's the problem. I'm trying to migrate Oracle data from an HP system to a Sun system using a raw device as a 'bridge' between the two systems. Both machines... (4 Replies)
Discussion started by: Neville
4 Replies
Login or Register to Ask a Question