grep only word matching the pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep only word matching the pattern
# 1  
Old 12-16-2009
grep only word matching the pattern

Hi gurus,
A file contains many words in format "ABC.XXXX.XXXX.X.GET.LOG" (X->varying). Now my shell script want this list (only words in formatABC.XXXX.XXXX.X.GET.LOG ) to continue the process. Pls help me.

Thanks,
Poova.
# 2  
Old 12-16-2009
Code:
nawk '
{
    for (o=1;o<=NF;o++){
        if ($o ~ /^ABC.*GET.LOG$/){
            print $o
        }
    }
}' file


Last edited by ichigo; 12-16-2009 at 10:40 AM..
# 3  
Old 12-16-2009
grep "ABC\.....\.....\..\.GET\.LOG" filename
# 4  
Old 12-16-2009
Quote:
Originally Posted by ichigo
Code:
gawk '
{
    for (o=1;o<=NF;o++){
        if ($o ~ /^ABC.*GET.LOG$/){
            print $o
        }
    }
}' file

I dont have gawk in my machine. awk and nawk are only there. pls suggest me an alternate way.

Thanks,
Poova

---------- Post updated at 08:06 PM ---------- Previous update was at 08:04 PM ----------

Quote:
Originally Posted by penchal_boddu
grep "ABC\.....\.....\..\.GET\.LOG" filename
This will give me the entire line. Just I want the word only.

Thanks,
Poova
# 5  
Old 12-16-2009
Quote:
Originally Posted by poova
I dont have gawk in my machine. awk and nawk are only there. pls suggest me an alternate way.
Code:
echo "gawk" | sed 's/^g/n/'

# 6  
Old 12-16-2009
Quote:
Originally Posted by poova

[/COLOR]
This will give me the entire line. Just I want the word only.

Thanks,
Poova
use -o option in grep.

Code:
grep -o "ABC\.....\.....\..\.GET\.LOG" filename

# 7  
Old 12-16-2009
-- /dev/null --

Last edited by ichigo; 12-16-2009 at 10:08 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script example to Grep matching word from file

Hi expert, Need help in shell script. a.txt file output is below i would like to grep 3 line and 1st column value which is admin\22226 only and not full line. i only know admin word as 22226 can come anything with admin\ in file. also after fetching it i would like to use this... (1 Reply)
Discussion started by: kuljeetpal
1 Replies

2. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

3. Shell Programming and Scripting

How to print few lines before and after matching word is found suing grep?

Hi, here are few lines present in the logs. I want to grep on Error and print few lines before and after Error word is found line1 Line2 Line3 Error Line4 Line5 Line6 Line7 I want the output to be Line2 Line3 Error Line5 (1 Reply)
Discussion started by: arghadeep adity
1 Replies

4. UNIX for Dummies Questions & Answers

Issues while pattern matching using grep

Hi, I have a file f1 wi the following data f1.txt ======== Report ID Report Name ----------------------------------------------------------------- Post Requests : 2 Post successes : 2 ============================================= I need to search for the... (2 Replies)
Discussion started by: RP09
2 Replies

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. Shell Programming and Scripting

Understanding pattern matching used in a grep command

I have the following code. I want to remove the --sort=num/num/... and am using grep to exclude it as shown below: I have a bit of problem figuring out the use of - at the front echo "--sort=4/5/6" | grep -ivE '-((sort|group)=+/+(/+)*)$' Now suppose I want to remove --quiet I can... (7 Replies)
Discussion started by: kristinu
7 Replies

7. Shell Programming and Scripting

Grep word between matched pattern

would like to print word between matched patterns using sed for example : create INDEX SCOTT.OR_PK ON table_name(....) would like to print between SCOTT. and ON which is OR_PK Please help me out Thanks (4 Replies)
Discussion started by: jhonnyrip
4 Replies

8. Shell Programming and Scripting

Extracting the strings matching a pattern from a word

Hi All , I need to extract the strings that are matching with the pattern : CUST.<AnyStringOfAnyLength>.<AnyStringOfAnyLength> from a file and then write all these string into another file. e.g. If a file SOURCE contains following lines : IF(CUST.ABCD.EFGH==1) THEN CUST.ABCD.EFGH =... (7 Replies)
Discussion started by: swapnil.nawale
7 Replies

9. Shell Programming and Scripting

matching a pattern in a file & prefixing a word

Hi, In my shell script i have to match a patten in a file , if found i have to prefix the entair line by a "word" eg. pattern = "aaa" prefix= #123 file: bbbb xxx zzzz aaaa qqqq kkkk outPut file: bbbb xxx ... (5 Replies)
Discussion started by: shivarajM
5 Replies

10. Shell Programming and Scripting

perl pattern matching vs. grep

I originally had a shell script that did a grep 10 times to pull out the number of times a certain pattern occured in a file: ie... aOccurances=`grep aPattern file|wc -l` bOccurances=`grep bPattern file|wc -l` ... ... ... fOccurances=`grep fPattern file|wc -l` As the file got bigger with... (0 Replies)
Discussion started by: junkmail426
0 Replies
Login or Register to Ask a Question