1831458 Members
3866 Online
110025 Solutions
New Discussion

Awk script

 
SOLVED
Go to solution
Aminur Rizal
Advisor

Awk script

Hi all,
I need to write a simple script (which is complex for me!) to get the following data:-
# cat data.txt
Record time : 200
Service : 2003e321
Potential duplicate : 0
Access time : 20041023
bla bla bla
..
..
thousands onf line

I worked out the following script to grep
only the interesting figures :-
#cat scripts.sh

/Record time/ {recordtime=$4}
/Service/ (service=$3}
/Access time/ {access=$4}
{print recordtime,service,access}

running awk -f script.sh data.txt
will result ONLY the first set of data captured by the scripts.

I know that I should create sort of loop so that it will continue to the next set of lines - can anyone help?
Aminur Rizal Afip
3 REPLIES 3
curt larson_1
Honored Contributor
Solution

Re: Awk script

give this a try

/^Record time/ {recordtime=$4;next;}
/^Service/ (service=$3;next;}
/^Access time/ {
printf("%d, %s, %d\n",recordtime,service,$4;}
Aminur Rizal
Advisor

Re: Awk script

Hi curt!
It works!
Really make my day. I give you 10 points for it!
Many thanks.
Aminur Rizal Afip
H.Merijn Brand (procura
Honored Contributor

Re: Awk script

# perl -pe '/^([\w ]+):\s*(.*)/?$p{$1}=$2:print@p{"Record Time","Service","Access time"}"' your_file

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn