![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep and display few lines before and after | melanie_pfefer | SUN Solaris | 13 | 02-19-2009 11:54 PM |
| grep a word and display its column | Orbix | UNIX for Dummies Questions & Answers | 1 | 12-24-2007 08:32 PM |
| How to display first 7 char of grep results? | kthatch | UNIX for Dummies Questions & Answers | 8 | 04-05-2007 01:00 AM |
| using cat and grep to display missing records | jxh461 | UNIX for Dummies Questions & Answers | 4 | 01-13-2007 09:56 AM |
| Grep and display | bobo | UNIX for Dummies Questions & Answers | 4 | 06-19-2006 02:42 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Make grep -c display like grep -n?
Hey Guys,
Wondering if there is a way to do the following I have a file called test.txt Code:
abc def abc abc def Code:
abc def so grep -n -f pattern.txt would show Code:
1:abc 2:def 3:abc 4:abc 5:def Code:
3:abc 2:def 2 means def occured 2 times in the file Is there a function or a clever way to achieve this? Thanks in Advance |
|
||||
|
Can't get grep to do all the work but a quick little script can do it
Say the script name is showdetails.sh Usage; showdetails /path_to/pattern.file /path_to/test.txt Inside the script.... #!/usr/bin/sh count=1 for nxt in `cat $1` do out[$count]="`grep -c $nxt $2`:$nxt\n" count=`expr $count + 1` done echo ${out[@]} | tr -d "[:blank:]" XX - END SCRIPT -- The tr will remove the blanks in the out put to get a nice neat colum, try it with the tr function and see. That should work, if my typing is ok... Goot go and do some firm upgrades in linux.... wish me luck.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|