search for a pattern using grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search for a pattern using grep
# 1  
Old 01-17-2012
search for a pattern using grep

Hi
I am facing the below problem.

I have set of lines in which i have to search for only the line which matches with the pattren "/" only.

input:-
Code:
/*+ some text */
/*+ some text */
/* Remove rows from a table of survey results. */
/* Add a survey respondent's name and answers. */
/* Remove rows from a table of survey results. */
/* Add a survey respondent's name and answers. */
/*sometext*/
SELECT salary / commission INTO sal_calc FROM employees_temp

output:-
Code:
SELECT salary / commission INTO sal_calc FROM employees_temp

the lines with /*+ or /* should be ignored.

i am using
Code:
egrep -w '\/' filename

but this is resulting me all the above rows.

please help.

Last edited by Franklin52; 01-17-2012 at 08:10 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-17-2012
Based on the input given .. Just give space before and after / in grep pattern ..
Code:
$ grep " / " infile
SELECT salary / commission INTO sal_calc FROM employees_temp

# 3  
Old 01-17-2012
Quote:
Originally Posted by jayan_jay
Based on the input given .. Just give space before and after / in grep pattern ..
Code:
$ grep " / " infile
SELECT salary / commission INTO sal_calc FROM employees_temp

sorry i missed to mention.
the statements may or may not have spaces in between.
so this dosen't work when statements do not have space before or after /
# 4  
Old 01-17-2012
Try this:
Code:
grep -v "^/\*" inputfile

An awk:
Code:
awk '/^\/\*/{next}'1 inputfile

# 5  
Old 01-17-2012
Smilie...
its not working..
it is giving me all the lines in my file and even lines with /*.
# 6  
Old 01-17-2012
Works for me.

Code:
$ cat inputfile
/*+ some text */
/*+ some text */
/* Remove rows from a table of survey results. */
/* Add a survey respondent's name and answers. */
/* Remove rows from a table of survey results. */
/* Add a survey respondent's name and answers. */
/*sometext*/
SELECT salary / commission INTO sal_calc FROM employees_temp
$
$ grep -v "^/\*" inputfile
SELECT salary / commission INTO sal_calc FROM employees_temp
$

Try this perl one-liner:
Code:
perl -ne '(!/^\s*\/\*/)&&print' inputfile

# 7  
Old 01-17-2012
the file has other lines also other than lines having only / like
Code:
/*+ some text */
/*+ some text */
/* Remove rows from a table of survey results. */
/* Add a survey respondent's name and answers. */
/* Remove rows from a table of survey results. */
/* Add a survey respondent's name and answers. */
/*sometext*/
SELECT salary / commission INTO sal_calc FROM employees_temp
some text some text some text
some text some text some text
some text some text some text
some text some text some text

in this sace it is printing the above 4 lines also.

Last edited by Franklin52; 01-17-2012 at 08:09 AM.. Reason: Please use code tags for code and data samples, thank you
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

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

3. Shell Programming and Scripting

Grep and BzGrep with Wildcard in Search Pattern

Hello All, I hope this is the right area. If not, Kindly let me know and I will report in the appropriate spot. I am needing to find a search pattern that will make the * act as Wildcard in the search pattern instead of being literal. The example I am using is bzgrep "to=<*@domain.com>"... (5 Replies)
Discussion started by: mancountry
5 Replies

4. UNIX for Advanced & Expert Users

Pattern Search with grep

Hello, I have a bunch of zip files like SS_SAMPLE_101_123.zip SS_101_123.zip SS_SAMPLE_121_345.zip SS_SAMPLE_222_678.zip SS_123_890.zip SS_.zip The 'ls' should search and list the files such as SS_101_123.zip and SS_123_890.zip alone. Could you please guide me with this.... (5 Replies)
Discussion started by: tinufarid
5 Replies

5. Shell Programming and Scripting

How can i use grep to search a specific pattern?

Hi All, My file contain the below data : w_SA_infa1.log:INFO : LM_36620 : () Command task instance : running command , with command value . Binary file w_SA_infa1.log.bin matches w_SA_infa2.log:INFO : LM_36620 : (30377|1427806528) Command task instance : running command , with command value... (1 Reply)
Discussion started by: aliva Dash
1 Replies

6. 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

7. Shell Programming and Scripting

pipe search pattern into a grep

comm -13 tmpfile tmpfile2 | grep -v <filename> >newfile so i want to 1. find records in 1 file bot not in another 2. The output of the first part is 1 field in a file with many fields. 3. find all the records that do not have the value piped from step #1 4. redirect to a new file ... (4 Replies)
Discussion started by: guessingo
4 Replies

8. HP-UX

recusrise pattern search with grep

Am new on hp-ux .. Found missing recursive pattern search grep -iR option that's there on Linux . Is any one know any way with grep or any advance command available on hp-ux using which i can search a word say "DbFnamesDatLimit" in all files under /etc on hp-ux in single step . my /etc... (3 Replies)
Discussion started by: Shirishlnx
3 Replies

9. UNIX for Dummies Questions & Answers

grep line pattern search

Hello everyone, I have been trying to get a list of all files containing a line of this type: };#followed by anything with any spaces (0 or more or 0 or more tabs) before the } and between each of the characters. I have been trying this : grep '*}*;*#*' *.c but I have not been fully... (1 Reply)
Discussion started by: gio001
1 Replies

10. Shell Programming and Scripting

search pattern by grep

hai folks, i am vijay very new to this website. My query: Search patterns from root directory to all directories by using grep (3 Replies)
Discussion started by: vijaysabari
3 Replies
Login or Register to Ask a Question