I wrote a prog. like below and is working fine. would like to know is there are any simple way to write the prog. New to unix so not sure of other ways.
Thanks in advance.
#!/bin/sh
echo "Enter filename..."
read name
cd /test/unix
cat $name | while read line
do
echo "$line" > tmpj
cat "tmpj" | egrep -c ora- > tmpk
if [ `cat tmpk` -gt 0 ]
then
cat tmpj | sed 's/.*\(ora-.....\).*/\1/' >> tmpl
fi
done
rm tmpj
rm tmpk
for var1 in `cat tmpl`
do
echo "$var1" > tmpj
cat tmpl | egrep -c `cat tmpj` > tmpk
if [ `cat tmpk` -gt 0 ]
then
echo "Error Code : "$var1" Count : `cat tmpk`"
sed "/$var1/d" tmpl > tmpm
mv tmpm tmpl
fi
done
rm tmpj
rm tmpk
rm tmpl
nawk '
{
a[$2]++
}
END {
for (i in a)
print "Error Code : " i " Count : " a
}
' file1.txt
---------- Post updated at 11:12 AM ---------- Previous update was at 11:10 AM ----------
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Thanks, excellent code.
The file which I had is an error message file and the ora errors are not always the 2nd col./occurence. ora error may appear anywhere in the line or wont appear also.
Apologies for the inconvenience.
eg.
nawk '
/ora-[0-9]/ {
for(i=1;i<=NF;i++)
if ( $i ~ /ora-[0-9]/ ) {a[$i]++;break}
}
END {
for (i in a)
print "Error Code : " i " Count : " a
}
' file1.txt
Thank you again for the prompt reply and it working fine and working much faster to my code(which I mentioned in the 1st post).
Nawk is something new to me, searched in the beginners unix book (by wrox) nothing much available.
Please correct me if Im worng :
The code is taking 'space' as the space separator.
and if the file is somewhat like this :
nawk '
/ora-[0-9]/ {
for(i=1;i<=NF;i++)
if ( $i ~ /ora-[0-9]/ ) { a[substr($i,index($i,"ora-"))]++; break}
}
END {
for (i in a)
print "Error Code : " i " Count : " a
}
' file1.txt
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Thank You.
The UNIX and Linux Forums
---------- Post updated at 07:51 AM ---------- Previous update was at 07:47 AM ----------
nawk '
/ora-[0-9]/ {
for(i=1;i<=NF;i++)
if ( match($i,/ora-[0-9]+/)) { a[substr($i,RSTART,RLENGTH)]++; break}
}
END {
for (i in a)
print "Error Code : " i " Count : " a
}
' file1.txt
Excellent gersh99, you are brilliant. Its working fine and working fast as well.
Can you please explain your code for the benefit of users like me or plz suggest some books where in I can gain some theoritical knowledge about shell prog using nawk.
---------- Post updated at 05:48 PM ---------- Previous update was at 05:33 PM ----------
Sorry guys for not using code tags, make sure next time i use it.