grep - searching for a specific string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep - searching for a specific string
# 1  
Old 01-05-2006
Question grep - searching for a specific string

ppl,

this is my "file" with fields

orderno orderdate orderdesc telno street city
1 01/04/2006 abc 123 100 tampa
2 01/04/2006 abc 123 100 tampa
3 01/04/2006 abc 123 100 tampa
4 01/04/2006 abc 123 100 tampa
5 01/04/2006 abc 123 100 tampa
6 01/04/2006 abc 123 100 tampa

searching for lines with ordernos 3,4 and 5 in a loop as:

ll=3
ul=5

while [ $ll -le $ul ]
do
grep '^$ll\>' file
ll=$((ll+1))
done

gives me null output.

pls help with the correct expression to retrieve the required lines. UNDERLINE.. the key to search is only the first field.. all other fields are same and can't be used. (p.s. however the expression is working with substituted values of $ll (if i hard code $ll with 3, 4 or 5.. i get correct results)

Thanks a lot in advance,
Sirisha
# 2  
Old 01-05-2006
From man sh

Code:
       Enclosing  characters  in  single quotes preserves the literal value of
       each character within the quotes.  A single quote may not occur between
       single quotes, even when preceded by a backslash.

       Enclosing  characters  in  double quotes preserves the literal value of
       all characters within the quotes, with the exception of $,  ?,  and  \.
       The  characters  $  and  ?  retain  their special meaning within double
       quotes.  The backslash retains its special meaning only  when  followed
       by one of the following characters: $, ?, ", \, or <newline>.  A double
       quote may be quoted within double quotes by preceding it with  a  back-
       slash.

Replace the ' quotes with "

grep "^$ll\>" file
# 3  
Old 01-05-2006
Thanks a lot Vino.. that was of really helpful!

regards
sirisha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep only words containing specific string

Hello, I have two files. All urls are space seperated. source http://xx.yy.zz http://df.ss.sd.xz http://09.09.090.01 http://11.22.33 http://canada.xx.yy http://01.02.03.04 http://33.44.55 http://98.87.76.65 http://russia.xx.zz http://aa.tt.xx.zz http://1w.2e.3r.4t http://china.rr.tt ... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

Grep string in a file and paste next line in a specific way

Hello, I know there are many questions and replies regarding grep command. What I would like to do is a bit different. File A: hello world welcome to my page this is my test site how are you I am fine, thank you where have you been I was in hospital really hope you are fine now Thanks,... (10 Replies)
Discussion started by: baris35
10 Replies

3. Shell Programming and Scripting

Grep and neglect a specific string

Hi, I have a file with "n" number of lines. I need to get rid of a specific line having a specific string from the file. I tried some possibilities but not successful. For ex: in a file named "test" hope should be removed along with the line. ... (8 Replies)
Discussion started by: ricky-row
8 Replies

4. UNIX for Dummies Questions & Answers

Grep contains specific string

i have file input dsgfdgdfgd> cab |egrep -i '(active|cbu)' 130502-11:34:11 10.133.1.153 9.0j stopfile=/tmp/15959 Trying password from ipdatabase file: /opt/ericsson/amos/moshell/sitefiles/ipdatabase... .. 0 1 CBU1 OFF ON 16HZ ROJ1192209/1 R5E TU8BZ04466... (3 Replies)
Discussion started by: radius
3 Replies

5. Shell Programming and Scripting

dynamic string searching for grep

hi my code is something like count=0 echo "oracle TABLESPACE NAME nd TARGET" while do count=`expr $count + 1` (1) tts_space_name$count=`echo $tts | cut -d "," -f$count` (2) target$count=grep $(tts_space_name$count)... (2 Replies)
Discussion started by: Gl@)!aTor
2 Replies

6. UNIX for Dummies Questions & Answers

How to grep cells that contain a specific string?

How do you grep cells that contain a specific string. I tried grep but it greps the whole line and not just the cells. Thanks! (4 Replies)
Discussion started by: evelibertine
4 Replies

7. UNIX for Dummies Questions & Answers

Grep Specific String In CSV

Hi All, I have a csv file like the following: "ABCD2","EFGH2","XXXX","1" "ABCD2","EFGH2","XXXX","2" I want to grep out the row which contains the value of 2 within the 4th column, so then i can use the extracted record to cut up and store into numerous variables. Obviously when... (3 Replies)
Discussion started by: RichZR
3 Replies

8. Shell Programming and Scripting

Searching for a specific string in a file

Hi I am trying to search for a certain set of patterns within a file, and then perform other commands based on output. testfile contents: password requisite pam_cracklib.so lcredit=-1 ucredit=-1 ocredit=-1 script: D="dcredit=-1" if then echo $D exists else echo $D doesnt... (8 Replies)
Discussion started by: bludhemn
8 Replies

9. UNIX for Advanced & Expert Users

How to perform Grep on many Gzip files, Searching for Specific information

Hello, I am wondering if you can assist with my question and ask kindly for this. I have a number of files that are listed as file1.gz through file100.gz. I am trying to perform a grep on the files and find a specific date that only resides within within one of the files. There are... (3 Replies)
Discussion started by: legharb
3 Replies

10. Shell Programming and Scripting

Searching for a specific string in an argumnet

I want to check the second argument for a specific string . The code below is what I am trying, but I get: UX:test (./test): ERROR: { if ($0 ~ /StringImLooking4/) {print $1} }: Unknown operator I want to test if the second argument contains the string StringImLooking4 Unixware 7 ... (1 Reply)
Discussion started by: dinplant
1 Replies
Login or Register to Ask a Question