Exact grep and count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exact grep and count
# 1  
Old 06-01-2013
Exact grep and count

got a file as y.txt

Code:
1 abc,def,ghj
2 defj,abc.kdm,ijk
3 lmn,cbk,mno
4 tmp,tmop,abc,pkl
5 pri,chk,cbk,lmo
6 def,cbk.pro,abc.kdm

i want to search in the above file the key word like abc

looking for two outcomes by passing the parameter value as abc into function and the two outocmes are :

1) how many lines the abc is available. It should search only for abc and not abc.kdm.

count should be 2.

2) also the line numbers of the respective lines where abc is available like below.

1 abc,def,ghj
4 tmp,tmop,abc,pkl


ck.sh abc

it should give two outcomes

can someone give me the solution for this ?

---------- Post updated at 10:10 PM ---------- Previous update was at 10:06 PM ----------

all doing in bash

Moderator's Comments:
Mod Comment edit by bakunin: first off, you are asking in the wrong forum. Second: this looks so much like homework and the question is so basic, that i suggest you take a look at the manpage of "grep" instead writing threads here. Anyway, this thread is closed.

Last edited by jim mcnamara; 06-01-2013 at 08:54 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Count exact matched words

hi , i have a file test.dat which contains following data. test.dat XY|abc@xyz.com XY|abc@xyz.com ST|abc@xyz.com ST|abc@xyz.com ST|XYZ@abc.com FK|abc@xyz.com FK|STG@xyz.com FK|abc@xyz.com FK|FKG@xyz.com i want to know the count of XY,ST,FK. i.e XY = 2 , ST = 3 , FK = 4 I am... (4 Replies)
Discussion started by: itzkashi
4 Replies

2. UNIX for Dummies Questions & Answers

Code for exact match to count occurrence

Hi all, I have an input file as below. I would like to count the occurrence of pattern matching 8th field for each line. Input: field_01 field_02 field_03 field_04 field_05 field_06 field_07 field_08 TA T TA T TA TA TA... (3 Replies)
Discussion started by: huiyee1
3 Replies

3. UNIX for Dummies Questions & Answers

Grep exact value

Hello All, I have a file all_info.txt Date Owner Filename 03/25/2014 mycomp\royale myfile_ goodfile_sec_20140324_c.zip 03/25/2014 mycomp\royale myfile_goodfile_sec_20140324_c.cpt 03/25/2014 mycomp\royale1 ... (9 Replies)
Discussion started by: kumar30213
9 Replies

4. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

5. UNIX for Dummies Questions & Answers

grep exact

FILE: #test file# server1 10.1.1.1 server2 10.1.1.2 server2-prv 10.1.1.3 grep -w "server2" {filename} Returns: server2 10.1.1.2 server2-prv 10.1.1.3 How would you just get it to return just the exact match line?: server2 10.1.1.2 Thanks! (4 Replies)
Discussion started by: trimike
4 Replies

6. Shell Programming and Scripting

How to grep the exact name?

I'm attempting to perform an exact match on an input data column with another input file but cannot figure out how to code the "grep" statement to handle 2 specific scenarios. I’m capturing the first column of data from $ifile2 into variable $rule and using it to perform a “grep” on $ifile3 to... (4 Replies)
Discussion started by: ltf1833
4 Replies

7. Shell Programming and Scripting

How to find lines that match exact input and count?

I am writing a package manager in BASH and I would like a small snippet of code that finds lines that match exact input and count them. For example, my file contains: xyz xyz-lib2.0+ xyz-lib2.0 xyz-lib1.5 and "grep -c xyz" returns 4. The current function is: # $1 is the package name.... (3 Replies)
Discussion started by: cooprocks123e
3 Replies

8. UNIX for Advanced & Expert Users

Exact Match thru grep ?????

hey..... i do have text where the contents are like as follows, FILE_TYPE_NUM_01=FILE_TYPE=01|FILE_DESC=Periodic|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=B FILE_TYPE_NUM_02=FILE_TYPE=02|FILE_DESC=NCTO|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=M... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

9. Shell Programming and Scripting

How to grep the exact name?

Hi All Here is one o/p from a program I have ... Can someone tell me the way so that I get only the output by the user "li" not the other users which have "li" in the name. Surely I dont like the idea Thanks a lot to all in advance C Saha (3 Replies)
Discussion started by: csaha
3 Replies

10. UNIX for Dummies Questions & Answers

grep - exact

I'm trying to use grep to search for a specific string. Given the following strings: .A BAGM4 0101 Z DH1300/PPD T/SF T/SD 10 .A CLUM4 0101 Z DH1300/PP T/SF T/SD 9 .A MQT 0101 Z DH1200/PPK T/SFK 2.0/SD 15 I only want to get the string that contains PPD. If I do the command: grep PPD... (9 Replies)
Discussion started by: wxornot
9 Replies
Login or Register to Ask a Question