Solved

need help in shell script to grep the space

Posted on 2014-04-15
9
652 Views
Last Modified: 2014-04-15
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
0
Comment
Question by:mac_g
  • 4
  • 3
9 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 40001193
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
 

Author Comment

by:mac_g
ID: 40001200
Thanks for your reply..

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

sh list.sh | awk '+$2 == 3'
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40001202
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:mac_g
ID: 40001211
apologies my mistake  ..

I got the required one from your advice ..

thanks lot for your help...

God Bless you
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40001219
Glad I could help!
0
 

Author Comment

by:mac_g
ID: 40001225
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
 

Author Comment

by:mac_g
ID: 40001256
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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Squid Connection Pools 3 70
Need script to search multiple files in one drive 13 48
SCP a file to multiple machines using a script 4 46
Run Secure WMI query from CentOS 5 35
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question