Pattern search using UNIX command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Pattern search using UNIX command
# 1  
Old 08-05-2013
Pattern search using UNIX command

Hi I would like to grep a text with pattern starting with $$WS_S. and ending with a delimiter space or comma.. please help me with the syntax
Eg:
Code:
aaaaaaaaasdjkghg $$WS_S.table1 sdef
dsf $$WS_S.table2,sdfdff
$$WS_S.table3 dasssssssssds

Moderator's Comments:
Mod Comment Use code tags please, see PM.

Last edited by zaxxon; 08-05-2013 at 11:07 AM.. Reason: code tags
# 2  
Old 08-05-2013
Show what you have tried so far, thanks.
# 3  
Old 08-05-2013
Code:
grep '\$\$WS_S.' filename|awk -F" " ' { if($NF=="2"){print$0} } '


Last edited by zaxxon; 08-05-2013 at 11:38 AM.. Reason: code tags
# 4  
Old 08-05-2013
You have 37 posts in this forum now. You should be familiar with code tags and got a PM and warning before, but still post without them, that's why you got an infraction now.

awk can do everything what grep can do and much more.
So 2 commands are not necessary.
awk does not need a single space as field separator, since this is part of the default. Default is a blank or any number/combination of spaces including tabs.
Your awk code is missing a blank between the "print" and "$0".
From your description I can't see if you want the whole line printed or just the part of it with the pattern; though the example would not be good for the 1st case, as this will always a match.

Anyway, if you grep supports "-o":
Code:
$ grep "\$\$WS_S\.[^ ,]\+" infile
aaaaaaaaasdjkghg $$WS_S.table1 sdef
dsf $$WS_S.table2,sdfdff
$$WS_S.table3 dasssssssssds
$ grep -o "\$\$WS_S\.[^ ,]\+" infile
$$WS_S.table1
$$WS_S.table2
$$WS_S.table3


Last edited by zaxxon; 08-05-2013 at 12:05 PM.. Reason: spelling
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

Grep command to search pattern corresponding to input from user

One more question: I want to grep "COS_12_TM_4 pattern from a file look likes : "COS_12_TM_4" " ];I am taking scan_out as the input from the user. How to search "COS_12_TM_4" in the file which is corresponds to scan_out (12 Replies)
Discussion started by: Preeti Chandra
12 Replies

3. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

4. Shell Programming and Scripting

Search file pattern using grep command

I 'm writing a script to search particular strings from log files. The log file contains lines start with *. The file may contain many other lines start with *. I need to search a particular line from my log file. The grep command is working in command line , but when i run my script, Its printing... (7 Replies)
Discussion started by: vinus
7 Replies

5. Shell Programming and Scripting

UNIX Shell Script Help for pattern search

Hi Need help for below coding scenario. I have a file with say 4 lines as below. DEFINE JOB TPT_LOAD_INTO_EMP_DET ( TDPID = @TPT_TDSERVER , USERNAME = @TPT_TDUSER ) ; ( 'DROP TABLE '||@TPT_WRKDB ||'.LOG_'||@TPT_TGT ||' ; ') , SELECT * FROM OPERATOR (FILE_READER) ; ) ; Now I want to... (5 Replies)
Discussion started by: Santanu2015
5 Replies

6. Shell Programming and Scripting

Pattern search (regular expression in UNIX)

Hello , Could anyone help me to define the string in regular expression way . Below is my string \rtf1\ansi\deff0{\fonttbl{\f0\fswiss Helv;}{\f1\fnil MS Sans Serif;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\lang1033\f0\fs16 The string will always start as \rtf1 and... (6 Replies)
Discussion started by: Pratik4891
6 Replies

7. Shell Programming and Scripting

Grep command is not search the complete pattern

I am facing a problem while using the grep command in shell script. Actually I have one file (PCF_STARHUB_20130625_1) which contain below records. SH_5.55916.00.00.100029_20130601_0001_NUC.csv.gz|438|3556691115 SH_5.55916.00.00.100029_20130601_0001_Summary.csv.gz|275|3919504621 ... (2 Replies)
Discussion started by: sumit.vedi1988
2 Replies

8. Shell Programming and Scripting

Pattern search using grep command !

Hi, I am trying to do pattern search using grep command. But i donot know what mistake i'm doing. I am not getting the expected Result. could any one please help me out? $ cat b.ksh AasdjfhB 57834B 86234B 472346B I want to print the line which is starting with either A or 8 and... (10 Replies)
Discussion started by: nikesh29
10 Replies

9. Shell Programming and Scripting

Using find command to search a pattern in group of files

Hi i am having a group of *.csh files under parent directory. Now i want to search a particular pattern in these group of *.csh files(suppose i need to search a pattern ABC - proj ). Can anyone please tell me how to do it using find command. Thanks in advance sarbjit (4 Replies)
Discussion started by: sarbjit
4 Replies

10. Shell Programming and Scripting

Search for awk pattern in unix env variable

For a Script I need to detemine which field of the unix environment variable SHLIB_PATH has the WALTDB entry. export SHLIB_PATH=/usr/user5/WALTDB/oracle/product/10.2.0/lib32:/usr/TZD/bin.wdad/mug/oracle/lib: echo $SHLIB_PATH | awk -F: '{ print $1 }' Shure gives me the first entry, but... (6 Replies)
Discussion started by: sdohn
6 Replies
Login or Register to Ask a Question