Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
Can someone help to write a script for formating data as given below
Input:
Client: shp13
Backup ID: shp13_1104610099
Policy: hp_shp13_app
Creator: root
Sched Label: Weekly
Schedule Type: UBAK (2)
Retention Level: 2 weeks (1)
Backup Time: Sun Jan 02 2005 04:08:19 (1104610099)
Elapsed Time: 5 second(s)
Expiration Time: Sun Jan 16 2005 04:08:19 (1105819699)
Kilobytes: 30620
Number of Files: 11
Keyword: Arch_appvcpClient: shp13
Backup ID: shp13_1104609818
Policy: hp_shp13_app
Creator: root
Sched Label: Weekly
Schedule Type: UBAK (2)
Retention Level: 2 weeks (1)
Backup Time: Sun Jan 02 2005 04:03:38 (1104609818)
Elapsed Time: 10978 second(s)
Expiration Time: Sun Jan 16 2005 04:03:38 (1105819418)
Kilobytes: 79988740
Number of Files: 648105
Keyword: SHP13PVCSFrom client to keyword the data will repeat n number of times.
Out Required:
Client,Backup ID,Policy,Creator,SChed Label,Schedule Type,Retention Level,Backup Time,Esalpsed Time,Expiration Time,Kilobytes,Number of Files,Keyword
shp13,shp13_1104610099,hp_shp13_app,root,Weekly,UBAK (2),2 weeks (1),Sun Jan 02 2005 04:08:19 (1104610099),5 second(s),Sun Jan 16 2005 04:08:19 (1105819699),30620,11,Arch_appvcp
shp13,shp13_1104609818,hp_shp13_app,root,Weekly,UBAK (2),2 weeks (1),Sun Jan 02 2005 04:03:38 (1104609818),10978 second(s),Sun Jan 16 2005 04:03:38 (1105819418),79988740,648105,SHP13PVCSPerl or Shell/awk will do
Thanks

This is a non-working start. It needs the ','.
sed -e 's/:/-/' infile | awk -F '-' 'BEGIN { ORS = '\012' } /Client-/,/Keyword-/ { printf %s,, $2 }'

nawk -f venu.awk infile
here's venu.awk
BEGIN {
FS=""
OFS=","
RS=""
}FNR==1{
for(i=1; i <= NF; i++)
printf("%s%s", substr($i,1,index($i,":")-1), (i==NF) ? "\n" : OFS);
}{
for(i=1; i <= NF; i++)
printf("%s%s", substr($i,index($i,":")+1), (i==NF) ? "\n" : OFS);
}

I've provided a Korn shell solution and another poster has provided an nawk solution. If you are doing this as part of your job, I'd suggest you learn how to do this yourself by buying a book. If it is a homework assignment, I'd suggest you read the book.
#!/bin/ksh
OLDIFS=$IFS
NEWIFS=":
"exec 3<./junk.data99
while read -u3 title data1 data2
do
if [[ $title = "Client" ]]
then
IFS=$NEWIFS
titleLine=""
dataLine=""
titleLine="$titleLine$title,"
dataLine="$dataLine$data1,"
elif [[ $title = "" ]]
then
:
elif [[ $title = "Keyword" ]]
then
IFS=$NEWIFS
titleLine="$titleLine$title"
dataLine="$dataLine$data1"
print $titleLine
print $dataLine
elif [[ $data1 = "Time" ]]
then
IFS=$OLDIFS
titleLine="$titleLine$title"
dataLine="$dataLine$data1$data2"
else
IFS=$NEWIFS
titleLine="$titleLine$title,"
dataLine="$dataLine$data1,"
fi
doneJerry Lemieux

intersting...
So if this's a part of your work - just "BUY a book".
And if this's a homework, then "READ the book".AM I getting it right?
Sorry - just kiddin'.

I meant that if it was homework, read the text book. If it was for the job, buy a book (and by extension) read it. I guess I wasn't paying much attention to what I was writing. A long day.

David/Vgersh/Jerry,
You guys are great. Thanks a lot for your help. All of your guidance was of great help.
Cheers

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |