The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C Shell Script query bpupdown Shell Programming and Scripting 1 05-13-2008 07:38 PM
shell script related query gopsman Shell Programming and Scripting 1 12-03-2007 12:50 AM
executing a SQL query in shell script lijju.mathew Shell Programming and Scripting 1 05-17-2007 11:29 AM
Query on a shell script logic tipsy Shell Programming and Scripting 1 06-29-2006 05:38 PM
Executing a SQL query from a shell script 98_1LE UNIX for Dummies Questions & Answers 3 03-23-2002 03:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-06-2008
max29583 max29583 is offline
Registered User
  
 

Join Date: Dec 2006
Location: UK
Posts: 33
Shell script query

Hi,

I am stuck assigning a value to a variable.
I am trying to assign a value to a variable but getting error....

IP_ADDR=grep 'I.P. Address' /install/cfgdist/`uname -n`.cfg | cut -d : -f 2| cut -d . -f 1-3| sed s/" "//g

I am using this script to grep first three octets of an IP address from a file and assign the value to IP_ADDR....but I am not able to assign the value to the variable...

Please some one help.

Regards,
Abhishek
  #2 (permalink)  
Old 08-06-2008
max29583 max29583 is offline
Registered User
  
 

Join Date: Dec 2006
Location: UK
Posts: 33
I tried like this after searching for it in the forums....

I=`grep 'I.P. Address' /install/cfgdist/`uname -n`.cfg | cut -d : -f 2 | cut -d . -f 1-3 | sed s/" "//g`

But its giving the error as:
abhits/39:[~] 183) ./abhi
./abhi: .cfg: not found
./abhi: -n: not found
Exit 1

If I run it on shell its working
abhits/39:[~] 185) grep 'I.P. Address' /install/cfgdist/`uname -n`.cfg
| cut -d : -f 2 | cut -d . -f 1-3 | sed s/" "//g
172.174.158

Please can someone help

Regards,
Abhi
  #3 (permalink)  
Old 08-06-2008
sank sank is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 23
If you are executing it from the script, try double quotes like this:
I="grep 'I.P. Address' /install/cfgdist/`uname -n`.cfg | cut -d : -f 2 | cut -d . -f 1-3 | sed s/" "//g"
  #4 (permalink)  
Old 08-06-2008
sank sank is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 23
Hi, the above maynot work.
Why not break the query into multiple statements and try executing each one of them and see which part is giving the error ?
  #5 (permalink)  
Old 08-07-2008
max29583 max29583 is offline
Registered User
  
 

Join Date: Dec 2006
Location: UK
Posts: 33
Hi Sank,
Ya it didn't work but thanks anyways...
I tried with putting ksh as the shell
#! /bin/ksh -p

and then using it like this
I=$(grep 'I.P. Address' /install/cfgdist/`uname -n`.cfg | cut -d : -f 2 | cut -d . -f 1-3 | sed s/" "//g)

and it worked

Thanks.
Regards,
Abhi
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0