![]() |
|
|
|
|
|||||||
| 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 |
| How to find out command has returned any value? | johnl | Shell Programming and Scripting | 1 | 07-28-2008 11:59 PM |
| returned from remote command | Frank2004 | HP-UX | 2 | 04-30-2008 08:29 AM |
| recording lines returned from fgrep... | DrRo183 | Shell Programming and Scripting | 3 | 04-07-2006 08:54 AM |
| Copying file names returned from a grep command into another directory | Kartheg | UNIX for Dummies Questions & Answers | 4 | 11-17-2005 09:34 AM |
| w/who command returned zero users | sinyem | UNIX for Advanced & Expert Users | 6 | 10-21-2003 08:06 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
number of lines returned from a grep command
hi all,
from a shell (ksh) script, i am doing a 'grep'. how do i find out the number of lines returned from that 'grep' command ?? thanks in advance. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
use grep -c option
|
|
#3
|
|||
|
|||
|
thanks for the reply. grep -c only Prints only a count of the lines that contain the pattern. i wanted the actual line and also the number of lines returned as well.
is there a way to check the length of a string in unix ?? i could possibly use this to see how many lines were returned. |
|
#4
|
||||
|
||||
|
Use AWK (nawk or /usr/xpg4/bin/awk on Solaris):
Code:
awk 'END{print c}/pattern/&&++c' input
Last edited by radoulov; 10-09-2008 at 03:09 PM. Reason: Corrected: c++ to ++c :) |
|
#5
|
|||
|
|||
|
line=$(grep -n "$pattern" "$filename" | cut -f1 -d':')
found=$(echo $line | awk '{print NF}' |
|||
| Google The UNIX and Linux Forums |