Search specific pattern in file and return number of occurence


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Search specific pattern in file and return number of occurence
# 1  
Old 07-02-2011
Search specific pattern in file and return number of occurence

Hi

I want to search for a specific pattern in file

Say

ABC;HELLO_UNIX_WORLD;PQR
ABC;HELLO_UNIX_WORLD_IS_NOT_ENOUGH;XYZ
ABC;HELLO_UNIX_FORUM;LMN

Pattern to search is : "HELLO_UNIX_*****" and not "HELLO_UNIX_***_***_"

I mean after "HELLO_UNIX" there can only be one word.In this case only WORLD and only FORUM qualifies. So output should be 2 in this case. As second row has more words after "HELLO_UNIX_"

Thanks in advance.
# 2  
Old 07-02-2011
Try:
Code:
perl -F";" -ane 'print if $F[1]=~/HELLO_UNIX_[^_]+$/' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 07-02-2011
Thanks bartus.

That was exactly what I was looking for. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Post Here to Contact Site Administrators and Moderators

Search for a pattern and replace a space at specific position with a Character in File

In file, we have millions of records each of 1000 in length. And at specific position say 800 there is a space, we need to replace it with Character X if the ID in that row starts with 123. So far i have used the below which is replacing space at that position to X but its not checking for... (3 Replies)
Discussion started by: Jagmeet Singh
3 Replies

3. Shell Programming and Scripting

Grep pattern after specific line number in a file

Hi guys, I am running a while loop in a script ro read a file line by line. Now I want to run a grep only on the lines below the line I am that is being read by the while loop. Eg: If my while loop is on line 4 of the file, the grep only runs below line 4 and does not include line 1,2... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

4. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 Replies

5. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

6. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

7. UNIX for Dummies Questions & Answers

How to search unique occurence in a file?

Hi, I have to search and count unique occurence of DE numbers in bold below in a file which has content like below. Proc Tran F-BUY Item Tkey Q5JV Item Tsid JTIZ9 Item Tdat 20091001 Item Tset 20091001 Item Tbkr 5 Item Tshs 2 Item Tprc 897.0 Item Tcom 2000.0 Item Tcm1 20091001... (6 Replies)
Discussion started by: akash028
6 Replies

8. Shell Programming and Scripting

Perl onliner to search the last line with an occurence of a pattern

Hi I need a perl onliner which seaches a line starting with a pattern(last occurence) and display it. similar to grep 'pattern' filename | tail -1 in UNIX Ex: I want to display the line starting with "cool" and which is a last occurence adadfadafadf adfadadf cool dfadfadfadfara... (4 Replies)
Discussion started by: ammu
4 Replies

9. Shell Programming and Scripting

Help with pattern search and return

I would like to write a script which will read a file containing a list of filenames of the format as shown below : /usr/local/packages/runcmdlinetool /home/john.doe/sdfsdf/sdfsdfsd/sdfsdf/sdfsdfTemplates.xml /usr/local/bin/gtar... (4 Replies)
Discussion started by: inditopgun
4 Replies

10. UNIX for Dummies Questions & Answers

Pattern occurence in a file

How can we find the number of occurence of a specified pattern in a file? This command would be a part of a shell script. (5 Replies)
Discussion started by: videsh77
5 Replies
Login or Register to Ask a Question