?
Solved

need help in shell script to grep the space

Posted on 2014-04-15
9
Medium Priority
?
665 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 1500 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
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 

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 1500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Utilizing an array to gracefully append to a list of EmailAddresses
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.
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…
Suggested Courses

718 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