need help in shell script to grep the space

one of my shell script display output in below format

-----output-----------
file11    2
file21    3
file31    2
file42    3
-------------------

where
first column is    --  FileName,
second  column is - its Count

------------
now  I want to display from above,  only rows which have the file count= 3

means .. from second column which has the count=3, then only  display that row.
---------
when I tried simply to grep for 3, then some file names include digits 3 within, having count different than required, also shown in output.
----------

please help
mac_gAdmin - Oracle Fusion Middleware suiteAsked:
Who is Participating?
 
woolmilkporcCommented:
Glad I could help!
0
 
woolmilkporcCommented:
Better use awk:

script.sh | awk '+$2 == 3'

You could grep for " 3" (space 3), but this will also show counts like "31". To avoid this you could grep for " 3$" (not " 3 ", because there is probably no space after the number!).
If there is sometimes a space following the number and sometimes not you can grep for " 3[ ]*$" (a space, "3", no space or any count of spaces, line end).

But the awk above will already take all this into account.
0
 
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
Thanks for your reply..

I am not getting anything  when applied below command,.....any futher customization required ?

sh list.sh | awk '+$2 == 3'
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
woolmilkporcCommented:
This is strange. Did you really post the original output?

Could it be that you're under Solaris? In this case please use "nawk"!
0
 
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
apologies my mistake  ..

I got the required one from your advice ..

thanks lot for your help...

God Bless you
0
 
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
I need one more small help in this regard

as of now I am getting required output want I needed


now I want to move files which has count 3  to some temp-directory.

count-3 means .. single file will be generated with three different extention.

for example : menu.ext1 , menu.ext2 & menu.ex3  

I want to move  all the above menu* three file to temp dir.

how to add this step in the same script.
0
 
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
coming again with all details from scratch difficult.
please allow this thread  to complete ..
as it is  about to finish..

Thanks  for your support
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.