Convert a script in awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert a script in awk script
# 8  
Old 06-09-2005
Quote:
Originally Posted by Lestat
Not yet, i still have problems:

example# nawk prueba.awk borrar

nawk: syntax error at source line 1
context is
>>> prueba. <<< awk
nawk: bailing out at source line 1
nawk -f prueba.awk borrar
# 9  
Old 06-09-2005
i got it....

nawk -f prueba.awk borrar

Thanx my friend vgersh99!!!!!!!!
# 10  
Old 06-09-2005
Thanx criglerj your solutions works too, but now i have a new problem, the file borrar.log have 2537051 lines and this process is taking 30 seconds, and i need this information for bein showed each 5 seconds, maximus 10... how can i do it better?
# 11  
Old 06-09-2005
Post a sample data file please. If the "0x000000??" appears in a foreseeable position, I think the "substr" procedure can be done in the END{} part.
# 12  
Old 06-10-2005
Quote:
Originally Posted by Lestat
Thanx criglerj your solutions works too, but now i have a new problem, the file borrar.log have 2537051 lines and this process is taking 30 seconds, and i need this information for bein showed each 5 seconds, maximus 10... how can i do it better?
If the data you're looking for always shows up in the same awk field, e.g., $4, and it's the only thing in that field, then you can speed it up as r2007 suggested, by only checking that field and by using the whole field as the index of arr, then deferring the substring operation to the END block:
Code:
$4 ~ /^0x000000(01|0B|45|58|64|66)$/ {
    arr[$4]++
}

END {
    for (i in arr)
        print "Errores", "0x" substr(i,9,2), arr[i]
}

My next line of attack would be ruby or perl. Ruby is easier to read and write, but it works by interpreting the AST at runtime. Perl runs faster because it compiles to bytecode. And I believe perl is installed by default on Solaris 8 (usually an old version, though sysadmins frequently install an updated version). Anyhow, a perl version would look like this:
Code:
while (<>) {
    next unless /0x000000(01|0B|45|58|64|66)/;
    $a{$1}++;
}
while (($k, $v) = each %a) {
    print "Errores 0x", $k, " ", $v, "\n"
}

# 13  
Old 06-10-2005
Part of my 'borrar' file:

[2005-06-10 07:28:11]{12}: [R-> PBRX1] DELIVER_SM_RESP [seqno: 79774][trans_id: 23914495 ][cmd_status: 0x00000064]
[2005-06-10 07:28:11]{13}: [R-> PBRX2] DELIVER_SM_RESP [seqno: 79775][trans_id: 23914496 ][cmd_status: 0x00000001]
[2005-06-10 07:28:11]{7}: [R-> PBRX2] DELIVER_SM_RESP [seqno: 79777][trans_id: 23914498 ][cmd_status: 0x00000066]
[2005-06-10 07:28:11]{12}: [R-> PBRX2] DELIVER_SM_RESP [seqno: 79776][trans_id: 23914497 ][cmd_status: 0x00000045]
[2005-06-10 07:28:12]{8}: [R-> PBRX1] DELIVER_SM_RESP [seqno: 79778][trans_id: 23914499 ][cmd_status: 0x00000000]

I hope this could help you
# 14  
Old 06-10-2005
... in one of my earlier posts, it was shown that running awk to count lines was actually slower than running a "grep-wc" combination ... try this one if it's any quicker ... sometimes speed is achieved just by using the tools at hand properly ...
Code:
#! /bin/ksh

E01=`grep -c 0x00000001 errores.log`
E0B=`grep -c 0x0000000B errores.log`
E45=`grep -c 0x00000045 errores.log`
E58=`grep -c 0x00000058 errores.log`
E64=`grep -c 0x00000064 errores.log`
E66=`grep -c 0x00000066 errores.log`
TOTAL=`expr $E01 + $E0B + $E45 + $E58 + $E64 + $E66`

echo "Errores 0x01 $E01" > class_total
echo "Errores 0x0B $E0B" >> class_total
echo "Errores 0x45 $E45" >> class_total
echo "Errores 0x58 $E58" >> class_total
echo "Errores 0x64 $E64" >> class_total
echo "Errores 0x66 $E66" >> class_total
echo "T O T A L $TOTAL" >> class_total

exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert XML to CSV using awk or shell script

Hello, I am working on a part of code where I need a awk or shell script to convert the given XML file to CSV or TXT file. There are multiple xml files and of different structure, so a single script is required for converting data. I did find a lot of solutions in the forum but... (16 Replies)
Discussion started by: Rashmitha
16 Replies

2. Shell Programming and Scripting

Help with convert awk script into perl

Input file (a list of input file name with *.txt extension): campus.com_icmp_ping_alive.txt data_local_cd_httpd.txt data_local_cd.txt new_local_cd_mysql.txt new_local_cd_nagios_content.txt Desired output file: data local_cd_httpd data local_cd new local_cd_mysql new ... (9 Replies)
Discussion started by: perl_beginner
9 Replies

3. Shell Programming and Scripting

Help: How to convert this bash+awk script in awk script only?

This is the final first release of the dynamic menu generator for pekwm (WM). #!/bin/bash function param_val { awk "/^${1}=/{gsub(/^${1}="'/,""); print; exit}' $2 } echo "Dynamic {" for CF in `ls -c1 /usr/share/applications/*.desktop` do name=$(param_val Name $CF) ... (3 Replies)
Discussion started by: alexscript
3 Replies

4. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

5. Programming

awk script to convert a text file into csv format

hi...... thanks for allowing me to start a discussion i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database.. the input text file is as follows:- USB History Dump by nabiy (c)2008 (1) --- Kingston DataTraveler 130 USB... (2 Replies)
Discussion started by: certteam
2 Replies

6. Shell Programming and Scripting

Help: how to convert perl script to awk in windows2003 server environment

For the following perl script, can anyone help to convert it to awk statement in windows2003 server environment ? Code: foreach $k (sort {$a <=> $b} keys %psnum) (1 Reply)
Discussion started by: tojzz
1 Replies

7. Shell Programming and Scripting

Awk script to convert csv to html

Hi Written some script to convert csv to html but could not add table headers.Below are the errors iam getting ./csv2html | more + awk -v border=1 -v width=10 -v bgcolor=black -v fgcolor=white BEGIN { printf("<table border=\"%d\" bordercolor=\"%s\" width=\"%d\"... (2 Replies)
Discussion started by: zeebala1981
2 Replies

8. Shell Programming and Scripting

convert this into csv using awk/shell script

Hi Scripting gurus, I need to convert following text snippet into csv. please help Input heading1 = data1 heading2 = data2 .. .. heading n = data n heading 1 = data1 .. .. Output data1,data2,....,data n (3 Replies)
Discussion started by: azs0309
3 Replies

9. Shell Programming and Scripting

how to convert unix .ksh script to windows .batch script

I am using awk in my .ksh script but when I am trying to run in windows its not recognising awk part of the ksh script , even when I changed it to gawk it does not work, this is how my .ksh and .bat files look like. thanx. #!/bin/ksh egrep -v "Rpt 038|PM$|Parameters:|Begin |Date: |End... (1 Reply)
Discussion started by: 2.5lt V8
1 Replies

10. Shell Programming and Scripting

here-doc convert 2 script convert to single script?

I have my main script calling another script to retrive a "ls -alt" of a directory that's located in a remote location I'm sftping into. main.sh #!/bin/ksh getLS.sh > output.txt getLS.sh #!/bin/sh /home<..>/sftp <host@ip> <<! cd /some/dir/Log ls -alt quit ! Basically I'd like to be... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question