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.
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
awk '{ if( NR == 1 ) { for ( i=1; i<=NF; i++ ) { arr = $i; } } else { for( i=1; i<=NF; i++ ) { printf "%s : %s\n", arr, $i } } }' filename
if you have Python, here's an alternative:
#!/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,
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.
anbu23
March 20, 2007, 3:54am
6
$ 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
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" "; }'
anbu23:
$ 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
Thank you very much.It's working.