Solved

need help in shell script to grep the space

Posted on 2014-04-15
9
658 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
Industry Leaders: 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ubuntu not booting - How get past GRUB? 3 76
Linux Samba using Kerberos to Auth from Active Directory 9 88
Linux FTP Error 5 44
Merging two files with Perl 5 25
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Fine Tune your automatic Updates for Ubuntu / Debian
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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