Egrep output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Egrep output
# 1  
Old 01-09-2016
Egrep output

If I have an output from egrep that has two elements on separate lines can I concatenate them? so the egrep for examople might be:

Code:
egrep "filename|type"

And the actual output might be:

Code:
./file001.doc
Type Text Document

How do I get the egrep to remove the line feed so the output is:

Code:
./file001.doc Type Text Document

???
Thanks in advance.

Last edited by Don Cragun; 01-09-2016 at 03:23 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 01-09-2016
Hello TuftyDave,

Request you to show sample Input_file with expected output sample. Could you please try following(not tested though) and let me know if this helps you.
Code:
awk '/filename/ || /type/{A=A?A OFS $0:$0;} /type/ && A{print A;A=""}' Input_file

Thanks,
R. Singh
# 3  
Old 01-09-2016
Hi Ravinder

I really wanted to know if there is a solution to this using egrep, as my inout is via find....
I understand that ASCII 08 or ^H is the backspace character, I was hoping to find out how to integrate that into the egrep output parameter...

Last edited by Don Cragun; 01-09-2016 at 03:26 PM.. Reason: Add ICODE tags.
# 4  
Old 01-09-2016
Hello TuftyDave,

Could you please post sample Input_file with sample output.


Thanks,
R. Singh
# 5  
Old 01-09-2016
This is one I was doing a couple of days ago, but the issue is the same...

From this one, I want the filename & the Camera Model to be o/p on the same line...
what I used is:
Code:
find -iname "*.jpg" -print0 | xargs -0 exiftool -a | egrep "===|Camera Model Name"

What it gives me is:
Code:
======== ./20150608_142304.jpg
Camera Model Name               : GT-I9100
======== ./20150608_142308.jpg
Camera Model Name               : GT-I9100
======== ./20150608_154859.jpg
Camera Model Name               : GT-I9100
======== ./20150610_090355.jpg
Camera Model Name               : GT-I9100
.... (etc)

What I want is:

Code:
======== ./20150608_142304.jpg Camera Model Name               : GT-I9100
======== ./20150608_142308.jpg Camera Model Name               : GT-I9100
======== ./20150608_154859.jpg Camera Model Name               : GT-I9100
======== ./20150610_090355.jpg Camera Model Name               : GT-I9100

So I want to modify the egrep op somehow to loose the line feed.

Last edited by TuftyDave; 01-09-2016 at 03:45 PM.. Reason: egrep grep
# 6  
Old 01-09-2016
You can't change the output format of egrep using egrep, although if you could directly grep the files instead of reformatting them using exiftool, you could just use:
Code:
fgrep 'Camera Model Name' /dev/null *.jpg

to print the lines containing Camera Model Name preceded by the name of the file that contained that line.

But you can use another filter to join lines together at the end of your current pipeline. For example:
Code:
find -iname "*.jpg" -print0 | xargs -0 exiftool -a | egrep "===|Camera Model Name" | paste -d ' ' - -

or you could replace the egrep with something that can select the desired lines and do some reformatting similar to what Ravinder was suggesting:
Code:
find -iname "*.jpg" -print0 | xargs -0 exiftool -a | awk '/===/{printf("%s ",$0)}/Camera Model Name/'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Egrep

Hi I am trying to run CMD that combining EGREP and PERL in multiple files cat *07:00.22-12-13.txt | egrep" NAME| perl -ne 'print if /^sid9/ .. /^!/' " I need the see the NAME and the text from sid9 to ! how can I use the EGERP in parallel to the PERL ? This is one file Qqq... (2 Replies)
Discussion started by: sharong
2 Replies

2. Shell Programming and Scripting

Using egrep to output expressions which are not found

Hi, Im using the below command to search a file for multiple expressions if the 4th expression doesnt exist the command simply lists what it can find and ignores what it cant. Is there any way to get the command to output an error or a message if it cant find the 4th expression to a file? ... (16 Replies)
Discussion started by: 02JayJay02
16 Replies

3. Shell Programming and Scripting

egrep output order

The order of egrep output seems to be as they occur in the file. How do I get the order as requested? For e.g. file contents: AAA EEE GGG egrep 'GGG|AAA|EEE' file gives AAA EEE GGG instead of GGG AAA EEE (2 Replies)
Discussion started by: madhavb
2 Replies

4. Shell Programming and Scripting

egrep help

hi, i'm using egrep -i to search thru some text files for keywords (also stored in a file). egrep does wildcard search aka %keyword% as long as the keyword is found, it will be spool to a file meaning if keyword is 'xyz' 123 aabgdggjxyzslgj 124 xyzgjksgjd returns 123... (8 Replies)
Discussion started by: bing
8 Replies

5. Shell Programming and Scripting

egrep

Hi, I am wondering if it's possible to link multiple patterns with egrep. Here here is what I am doing : grep -v ";;" | grep -v ARC_TIME | grep -v \* | grep -v STAS0 Can I do all of this by invoking egrep just once ? Thanks (4 Replies)
Discussion started by: Aswex
4 Replies

6. Shell Programming and Scripting

egrep output each file in new line

I have the following script that searches in several files and shows the search results and the matches filename on the screen. find . -exec egrep -wH "word1|word2" {} \; the output from the search display as: file1 word1 word2 I need to show each file search output result on new... (5 Replies)
Discussion started by: konddor
5 Replies

7. Shell Programming and Scripting

How to grep/awk/egrep two values for given output?

Dear Friends, I have a command which can result following output. Packet is: /var/adm/yyyy/pkt6043 Intended for network : /vob/repo I would like to retrive pkt6043 and /vob/repo using single command. Blue color test will be always contstant and red color text will be dynamic ... (2 Replies)
Discussion started by: baluchen
2 Replies

8. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

9. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

10. Shell Programming and Scripting

Comma Delimited Output w/ egrep

Hi all, I have an input file that I am pulling out certain phases using the following commands: cat /nodes.txt | egrep -e 'OSVersion|PrimaryNodeName' Currently the output looks like this: OSVersion - 5.0 PrimaryNodeName - serverA OSVersion - 5.0 PrimaryNodeName - serverB OSVersion... (2 Replies)
Discussion started by: indianadoug
2 Replies
Login or Register to Ask a Question