grep / nawk issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep / nawk issue
# 1  
Old 02-11-2010
grep / nawk issue

I have a report which contains the following:
Code:
      Count  Value      %

         47 [  ]    69.12
         18 [0 ]    26.47
          3 [ 0]     4.41

I want to grep the total on the bottom [ ] brackets and store in a variable. However this may have a different figure everyday.

To read the [ 0] i do:
Code:
MATCH4=`grep "\[ 0\]" x.report.rpt | nawk '{print $1}'`

but how do i look for a number i.e. [ 3] , [ 10], [ 100] to get:
Code:
echo $MATCH4 - 3
echo $MATCH4 - 10
echo $MATCH4 - 100

etc...


---------- Post updated at 05:11 PM ---------- Previous update was at 05:10 PM ----------

please disregard i wrote the post wrong i have since resolved it thanks

Last edited by Scott; 02-11-2010 at 04:36 PM.. Reason: Code tags, please...
# 2  
Old 02-12-2010
Code:
sed -n '$s/.*\[ *\([0-9]*\)\].*/\1/p' reportfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Issue with Grep

Hi guys, Hope someone can help me with this - I'm sure it's fairly simple but it's driving me mad! (forgive the coding - still new on scripting - come from Windows) I have the following coding for checking whether I want to include a line in a file:- EXTRACT_Date=$(date --date="${PERIOD}"... (6 Replies)
Discussion started by: NickF
6 Replies

2. Shell Programming and Scripting

Use of -r, grep, nawk in script

Hello Friends, I am new to unix shell, need to understand the meaning of few cmds in below script, #!/usr/bin/ksh FTP_FILE_NAME="$1" if then grep "TRLR@@@@@@" $FTP_FILE_NAME | nawk -F"" '{print $2}' else echo "0" fi what is the use of -r, grep, nawk & -F in above script. Why... (2 Replies)
Discussion started by: DK2014
2 Replies

3. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

4. Shell Programming and Scripting

Substitution Issue with nawk

Hi, I'm trying to reformat some badly formatted XML that I've extracted from Oracle clob columns using the following nawk command: nawk '{gsub(/</,/>\n/); print}' test.raw > test.xml the substitution executes fine, but instead of subbing < with > followed by newline, it subs the < with a... (3 Replies)
Discussion started by: sffuji
3 Replies

5. Shell Programming and Scripting

issue with nawk while using variable assignment

#ifconfig -a | nawk '/1.1.1.1/{print}' inet 1.1.1.1 netmask xxxxxxxxx broadcast 0.0.0.0 If i assign the ip to a variable and search for the variable nothing gets printed!! # ifconfig -a | nawk -v ip=1.1.1.1 '/ip/{print}' I am not able to understand why this is happening! (6 Replies)
Discussion started by: chidori
6 Replies

6. Shell Programming and Scripting

nawk issue

Hi, Below work fine, whenever any character puts, however if we use "(", it's not working. Working =============== echo 'Sau(rabh is Nice' | nawk -v a="Saurabh" '{print substr($1,1,match($1, "u"))}' Not working ==================== echo 'Sau(rabh is Nice' | nawk -v a="Saurabh" '{print... (3 Replies)
Discussion started by: sbaisakh
3 Replies

7. Shell Programming and Scripting

issue with toupper in nawk

Hi All, I am seeing an issue while using toupper in nawk. Below is the code that I am using.Toupper method is not working as expected in this case.nawk 'NR==FNR{a=$4" "$5}NR>FNR{print NF?$0:a"\n";if(/^cn:/) x=toupper($0)}' FS="" id_list.txt attributes.txt > out In the above script, id_list... (9 Replies)
Discussion started by: Samingla
9 Replies

8. Shell Programming and Scripting

grep, awk, nawk combo

I have 2 files: File1 "aa","server","001-9031234-001", File2 001-9031234-001|12345 Both files have many lines of text. Each line needs to be evaluated. I need to look at the value of the third field in File 1. Then look for that same value in File 2 and assign the value of Field 2... (5 Replies)
Discussion started by: scriptr2be
5 Replies

9. UNIX for Dummies Questions & Answers

what is the similar command for "grep -v" in nawk?

Can any one please say about the below, using, grep -v "name" file.txt the result of above command will be it will print all the lines except the line which having the word "name" similarly, nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=0 a=1 s="name" file.txt ... (7 Replies)
Discussion started by: prsam
7 Replies

10. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies
Login or Register to Ask a Question