LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-03-2014, 03:13 PM   #1
Automatic
Member
 
Registered: Mar 2013
Posts: 42

Rep: Reputation: Disabled
Only grep part of a line, but, output the full line?


So, I have program $a that shoves out a bunch of data, but, only the data before $z is what I want to grep for, anything after $z isn't important to the grep, but, is after the grep, so, what I need to do is something like:-

Code:
$a | sed "s/^(.*?)$z.*/\1/" | grep "$s" | $hereIsWhereIwantTheOriginallyDataBeforeISed'dItForTheGrepToNotSearchAfterThe$z.
is this possible?

For a more details reason, I need to search for all images that are 16:9 in a DIR, so, I do (This is a VirtualMachine, if you're wondering why I'm running as root):-
Code:
identify -format "%[fx:w/h] - %M\n" /root/folder/*
Which gives me:-
Code:
1.77778 - /root/folder/1.jpg
1.77778 - /root/5738554/2.jpg
1.62866 - /root/5738554/This file is on purposely stating the phrase 1.77778 to make it hard to just grep this.jpg
1.465 - /root/5738554/4.jpg
1.77778 - /root/5738554/5.jpg
1.77778 - /root/5738554/6.jpg
1.50037 - /root/5738554/7.jpg
1.77778 - /root/5738554/8.jpg
1.77778 - /root/5738554/9.jpg
1.6 - /root/5738554/10.jpg
1.61426 - /root/5738554/11.jpg
1.61426 - /root/5738554/12.jpg
1.77778 - /root/5738554/13.jpg
1.6 - /root/5738554/14.jpg
1.50038 - /root/5738554/15.jpg
1.49393 - /root/5738554/16.jpg
1.77778 - /root/5738554/17.jpg
1.78087 - /root/5738554/18.jpg
Passing that through sed:-
Code:
sed 's/\(.*\) - .*/\1/'
Gives me:-
Code:
1.77778
1.77778
1.62866
1.465
1.77778
1.77778
1.50037
1.77778
1.77778
1.6
1.61426
1.61426
1.77778
1.6
1.50038
1.49393
1.77778
1.78087
Now, that's much easier to grep, just a quick:-
grep 1.77778

But, now all I get is a huge list of 1.77778, what I really want is to get the original list back, but, only the lines that passed the grep without the file names (As the file names could include 1.77778)

So, how do I get the result before the sed with only the lines that passed the grep? Is this possible, or, do I have to create my own program to do this?

Last edited by Automatic; 04-03-2014 at 03:46 PM.
 
Old 04-03-2014, 03:44 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
why not just:

Code:
identify -format "%[fx:w/h] - %M\n" /root/folder/* | grep '^1.77778'

Last edited by estabroo; 04-03-2014 at 03:49 PM. Reason: code tags and clarified grep
 
Old 04-03-2014, 03:46 PM   #3
Automatic
Member
 
Registered: Mar 2013
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by estabroo View Post
why not just:

grep '^1.77778'
Because I was unware this was a thing, thanks, solves the issue!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Remove new line in the output of grep command massy Programming 2 03-09-2014 03:57 AM
grep query to list 1 line [which is fixed] and the next line after it [variable text] Glenn D. Linux - Software 3 01-20-2011 07:21 AM
Want to print fouth line after resulted line using grep with tail command saurabhmehan Linux - Newbie 10 08-05-2010 12:38 AM
shell script find a line and the next line (grep?) metalx1000 Programming 5 07-24-2007 09:41 PM
Grep's line numbers parsed into one line of output. judgex Programming 8 08-14-2006 05:22 AM


All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration