If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Shell script pattern matching

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-05-04, 10:14
sachin_mt sachin_mt is offline
Registered User
 
Join Date: Jan 2003
Posts: 106
Shell script pattern matching

We are writing a shell script for installing a website on linux/solaris machine.

Since we donno shell script we are struggling a lot,and no proper persons to help us here. Our requirement is

Assume I have a file say sachi.txt

It has

Abc
Ssd
Sds
/opt="/opt/sourcecode"
sds

Now we have a shell script which has

Read a

And assume a=sourcecode
Now we need to search sachi.txt for sourcecode pattern and get /opt/sourcecode in a shell variable say $res

You send us the best possible method to do this.
__________________
Sachi
Reply With Quote
  #2 (permalink)  
Old 04-05-04, 10:40
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Depending on what you want to get into the variable :
Code:
# Get line /opt="/opt/sourcecode"
res=`grep "$a"  sachi.txt

# Get "/opt/sourcecode"
res=`awk -F'=' '$0 ~ Pattern { print $2 }' Pattern="$a"`

# Get /opt/sourcecode
res=`awk -F'"' '$0 ~ Pattern { print $2 }' Pattern="$a"`
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 04-06-04, 02:44
sachin_mt sachin_mt is offline
Registered User
 
Join Date: Jan 2003
Posts: 106
we tried what u said, but

the first line

res=`grep "$a" sachi.txt

worked fine.

but the second stmt
res=`awk -F'=' '$0 ~ Pattern { print $2 }' Pattern="$a"`

did not work
when i execute it,it waits for user input and does nothing

and you are not using the res variable which has the search string in the second statement at all.

i think it should be
res=`awk -F'=' '$0 ~ Pattern { print $2 }' Pattern="$res"`

but how do i solve the "Waiting for user input problem"
__________________
Sachi
Reply With Quote
  #4 (permalink)  
Old 04-06-04, 03:01
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
I forgot the input file for awk commands :
Code:
# Get line /opt="/opt/sourcecode"
res=`grep "$a"  sachi.txt

# Get "/opt/sourcecode"
res=`awk -F'=' '$0 ~ Pattern { print $2 }' Pattern="$a" sachi.txt`

# Get /opt/sourcecode
res=`awk -F'"' '$0 ~ Pattern { print $2 }' Pattern="$a" sachi.txt`
These are 3 independant commands, you chooses one depending on the result you need (third i think).
__________________
Jean-Pierre.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On