Grep show file name once


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Grep show file name once
# 1  
Old 04-27-2014
Grep show file name once

I am using grep as follows

Code:
grep --include \*.org -ir "sunspot" -C 3 ./astron_aphys/solarsy/sun/helioseism/localhs/fhankel/

This gives me the filename for each matched line. How can I change the command to print the file name only once rather than having the same file name repeated at every line
# 2  
Old 04-27-2014
kristinu,
Please show your output. To obtain unique output, you can pipe the results from grep to
Code:
sort | uniq

or better yet
Code:
sort -u

commands.
# 3  
Old 04-27-2014
Pipe your grep to this post processor
Code:
awk '$0=="--" {print; next} {fname=line=$0; sub(/[:-].*/,"",fname); sub(/.*[:-]/,"",line)} fname!=oldfname {print "File="fname; oldfname=fname} {print line}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep command to show the number of results

Hi I wanted to know if there is an option in grep command to show the number of results (not the number of lines of findings). Thanks (14 Replies)
Discussion started by: abdossamad2003
14 Replies

2. Shell Programming and Scripting

Grep: show only first match per line?

Hi, can I make grep stop after finding the first occurrence of a regex in a line? Given: file with various regex patterns file to be grep'ed Sadly some of the regex patterns cannot be limited any further, so grep -Eiof patterns.txt file.txt (GNU grep 2.20) will give me possibly n hits... (4 Replies)
Discussion started by: stresing
4 Replies

3. Shell Programming and Scripting

Grep into a file + show following lines

Hi guys, This is probably very easy but I've no idea how to pull this out. Basically, I need to find errors into a very large logfile. When you grep the ID, the output is like this: +- Type: 799911 Code: Ret: 22728954 Mand: X Def: Des: UserDes: SeqNo: 2 +- Type: 799911 Code: Ret:... (5 Replies)
Discussion started by: Arkadia
5 Replies

4. UNIX for Dummies Questions & Answers

grep to show patterns being matched (-f option)

I have a list of patterns (regexes) in a file and use with `grep -f <file_with_list_of_regexes.txt> input.txt` to search in my input for those patterns. grep is doing a fantastic job at it and finds me the matching input text but I also want to see in the output the regex (from... (1 Reply)
Discussion started by: mirage
1 Replies

5. Shell Programming and Scripting

Grep command to show only process name

Can I modify the grep command to show only a process name? Currently I run ps -efa | grep chk_web to get the following: mousr 3395 1 0 09:36:06 pts/10 0:00 sh /var/opt/scripts/chk_web.sh Can this be changed in any way to get only: /var/opt/scripts/chk_web.sh or chk_web.sh. I... (3 Replies)
Discussion started by: runnerpaul
3 Replies

6. Shell Programming and Scripting

Show date/time with tail|grep command

Hi, I have a log file without date/time, and I want that everytime tail|grep find something it displays the date/time and the line. I have tried something like this command but without any luck to display the date/time: tail -F catalina.out | sed "s/^/`date `/" | egrep ... (6 Replies)
Discussion started by: julugu
6 Replies

7. Shell Programming and Scripting

grep to show date/time of file the string was found in.

I've seen several examples of grep showing the filename the string was found in, but what I really need is grep to show the file details in long format (like ls -l would). scenario is: grep mobile_number todays_files This will show me the string I'm after & which files they turn up in, but... (2 Replies)
Discussion started by: woodstock
2 Replies

8. Shell Programming and Scripting

Show file to new format

Hi all If my text file as follow: group size time file other 58585739 2008 test1.csv other 122 2008 testcsv.sh other 164 19:28 testexplain.sh other 29132428 2008 testq.csv other 104 21:02 testshell.sh other 792 21:39 xxx.txt I need to show file to new format as follow: group... (1 Reply)
Discussion started by: almanto
1 Replies

9. Shell Programming and Scripting

Grep string but also it will show the next 5 lines

Hi experts, I want to grep a number 9366109380 from a file but it will also show me the next 5 lines. Below is the example- when i grep 989366109380, i can also see the next 5 lines. Line 1. <fullOperation>MAKE:NUMBER:9366109380:PPAY2;</fullOperation> Line 2.... (10 Replies)
Discussion started by: thepurple
10 Replies

10. Shell Programming and Scripting

grep to show lines only after pattern

When i grep for a pattern the search results comes up with matching lines(some before the pattern and some after)...how can i limit the search so that it shows only the lines after the pattern specified (5 Replies)
Discussion started by: wannalearn
5 Replies
Login or Register to Ask a Question