Sponsored Content
Top Forums Shell Programming and Scripting Make grep -c display like grep -n? Post 302086550 by blowtorch on Thursday 24th of August 2006 09:05:34 PM
Old 08-24-2006
I don't know if you could do this without reading the file line-by-line, but here goes:
Code:
while read pattern; do
   count=$(grep -c $pattern test.txt); 
   echo $count:$pattern; 
done < pattern.txt

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep and display

I have the following data: A 1 2 3 A 4 5 6 A 7 8 9 I want to grep this data with A and 3 lines below it then display them in this format: A 1 2 3 A 4 5 6 A 7 8 9 (4 Replies)
Discussion started by: bobo
4 Replies

2. UNIX for Dummies Questions & Answers

How to display first 7 char of grep results?

My file contains the following: uat2000.aspclient.active=true uat2001.aspclient.active=true uat2002.aspclient.active=true uat2003.aspclient.active=true uat2004.aspclient.active=false uat2005.aspclient.active=false uat2006.aspclient.active=false uat2007.aspclient.active=false... (8 Replies)
Discussion started by: kthatch
8 Replies

3. Shell Programming and Scripting

How to Grep for particular word and display..

Hi Guru's.... I've one log file in all my systems which writes the backup information.. I'have written a command like this: ssh -l ora${sid} ${primaryhost} "tail -50 /oracle/$ORACLE_SID/newbackup/END_BACKUP.log" |grep 'insert' |tail -1| awk '{print $7}' We have nearly 50 systems in our... (2 Replies)
Discussion started by: suri.tyson
2 Replies

4. Shell Programming and Scripting

grep display word only

Folks, is it possible to display only words with grep (or any built-in ultility)? I have more than 1 pattern to search, say apple & orange The text goes like this: So I need to display all the words starting with apple or orange The output should be: Any idea? (7 Replies)
Discussion started by: bsddaemon
7 Replies

5. Solaris

grep and display few lines before and after

Hi is there a way in grep to display few lines before and after the pattern?? I tried options A and B and after-context and before-context. But they don't work on Solaris platform. please advise. (13 Replies)
Discussion started by: melanie_pfefer
13 Replies

6. AIX

How to make grep stop at first match

I use grep to check for a string that validates data in a file, it works great but the problem is that the file is becoming too big and gerp has started hurting the response time to users. Since I only need to find the first occurrence I have been looking for ways to stop grep for scanning the rest... (8 Replies)
Discussion started by: mpoblete
8 Replies

7. UNIX for Dummies Questions & Answers

how to make this grep command

/usr/xpg4/bin/grep -e "Type" / datarecords.txt output datarecords.txt: male | datarecords.txt: male | datarecords.txt: female i wanna the output to be :male | :male | :female at the end not to appear the filename fom grep command :D :D (3 Replies)
Discussion started by: teefa
3 Replies

8. UNIX for Advanced & Expert Users

find/grep two items and display both

I have a file against which I can grep a string for. I can also check for that string count using wc -l (or grep -c). I need to display the results of both in one output i.e. 'line containing string' and 'count' - what would be the most efficient way of managing this? Thanks in advance. (3 Replies)
Discussion started by: haider1
3 Replies

9. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

10. UNIX for Dummies Questions & Answers

Using grep to make a header

How would I do the following : Records other than ”ATOM”,”CONNECT”, ”HETATM”, ”TER” and ”END” are considered header records which describe the metadata about the molecule. Use grep to generate the header. I have this chemistry database. On the attachment. But I am not sure how to use... (4 Replies)
Discussion started by: homeylova223
4 Replies
subst(n)						       Tcl Built-In Commands							  subst(n)

__________________________________________________________________________________________________________________________________________________

NAME
subst - Perform backslash, command, and variable substitutions SYNOPSIS
subst ?-nobackslashes? ?-nocommands? ?-novariables? string _________________________________________________________________ DESCRIPTION
This command performs variable substitutions, command substitutions, and backslash substitutions on its string argument and returns the fully-substituted result. The substitutions are performed in exactly the same way as for Tcl commands. As a result, the string argument is actually substituted twice, once by the Tcl parser in the usual fashion for Tcl commands, and again by the subst command. If any of the -nobackslashes, -nocommands, or -novariables are specified, then the corresponding substitutions are not performed. For example, if -nocommands is specified, command substitution is not performed: open and close brackets are treated as ordinary characters with no special interpretation. Note that the substitution of one kind can include substitution of other kinds. For example, even when the -novariables option is speci- fied, command substitution is performed without restriction. This means that any variable substitution necessary to complete the command substitution will still take place. Likewise, any command substitution necessary to complete a variable substitution will take place, even when -nocommands is specified. See the EXAMPLES below. If an error occurs during substitution, then subst will return that error. If a break exception occurs during command or variable substi- tution, the result of the whole substitution will be the string (as substituted) up to the start of the substitution that raised the excep- tion. If a continue exception occurs during the evaluation of a command or variable substitution, an empty string will be substituted for that entire command or variable substitution (as long as it is well-formed Tcl.) If a return exception occurs, or any other return code is returned during command or variable substitution, then the returned value is substituted for that substitution. See the EXAMPLES below. In this way, all exceptional return codes are "caught" by subst. The subst command itself will either return an error, or will complete successfully. EXAMPLES
When it performs its substitutions, subst does not give any special treatment to double quotes or curly braces (except within command sub- stitutions) so the script set a 44 subst {xyz {$a}} returns "xyz {44}", not "xyz {$a}" and the script set a "p} q {r" subst {xyz {$a}} returns "xyz {p} q {r}", not "xyz {p} q {r}". When command substitution is performed, it includes any variable substitution necessary to evaluate the script. set a 44 subst -novariables {$a [format $a]} returns "$a 44", not "$a $a". Similarly, when variable substitution is performed, it includes any command substitution necessary to retrieve the value of the variable. proc b {} {return c} array set a {c c [b] tricky} subst -nocommands {[b] $a([b])} returns "[b] c", not "[b] tricky". The continue and break exceptions allow command substitutions to prevent substitution of the rest of the command substitution and the rest of string respectively, giving script authors more options when processing text using subst. For example, the script subst {abc,[break],def} returns "abc,", not "abc,,def" and the script subst {abc,[continue;expr {1+2}],def} returns "abc,,def", not "abc,3,def". Other exceptional return codes substitute the returned value subst {abc,[return foo;expr {1+2}],def} returns "abc,foo,def", not "abc,3,def" and subst {abc,[return -code 10 foo;expr {1+2}],def} also returns "abc,foo,def", not "abc,3,def". SEE ALSO
Tcl(n), eval(n), break(n), continue(n) KEYWORDS
backslash substitution, command substitution, variable substitution Tcl 7.4 subst(n)
All times are GMT -4. The time now is 02:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy