![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep and display few lines before and after | melanie_pfefer | SUN Solaris | 8 | 2 Weeks Ago 08:05 AM |
| grep a word and display its column | Orbix | UNIX for Dummies Questions & Answers | 1 | 12-24-2007 04:32 PM |
| How to display first 7 char of grep results? | kthatch | UNIX for Dummies Questions & Answers | 8 | 04-04-2007 10:00 PM |
| using cat and grep to display missing records | jxh461 | UNIX for Dummies Questions & Answers | 4 | 01-13-2007 05:56 AM |
| Grep and display | bobo | UNIX for Dummies Questions & Answers | 4 | 06-19-2006 11:42 AM |
|
|
Submit Tools | LinkBack | Thread Tools | 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 |
| Forum Sponsor | ||
|
|
|
|||
|
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.. |
|||
| Google The UNIX and Linux Forums |