Solved

need help in shell script to grep the space

Posted on 2014-04-15
9
659 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.
Suggested Courses

739 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