Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 27 Nov 2014, 18:05
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Need end of vari. string value. (REALLY SOLVED)
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [10 Posts]  
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Tue 29 Nov 2005, 23:05    Post subject:  Need end of vari. string value. (REALLY SOLVED)  

I'm using a lanpup.cfg file to feed values to my setup script, looks like:

SERV=160SEA
SMBHOME=PUPPYPC
PW=guest
USRMODE=file

I need to get the value after the "=", a simple thing, except for me that is.

SERV=`cat /sbin/lanpup.cfg | grep -i "SERV=" | sed s/^.*$//`
______________________________________________^
Can't see how to cut the first part off, what goes above here?
Or is there a better way to do it? The wanted segment is unknown in length, I'm stumped.
In VB to get the end of the SERV= string would be: S = Right$(String, Len(String) - 5).

Quote by Jeremy Anderson:
"There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence."

Last edited by sunburnt on Fri 02 Dec 2005, 01:30; edited 1 time in total
Back to top
View user's profile Send private message 
Guest
Guest


PostPosted: Tue 29 Nov 2005, 23:30    Post subject:  

you could try

# eval `grep 'SERV=' /sbin/lanpup.cfg`
# echo $SERV
160SEA
#
Back to top
MU


Joined: 24 Aug 2005
Posts: 13644
Location: Karlsruhe, Germany

PostPosted: Tue 29 Nov 2005, 23:43    Post subject:  

SERV=`cat /sbin/lanpup.cfg | grep -i "SERV=" | sed s/^.*=//`

^ : from the beginning
.*= : whatever char until the last "="

Mark
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Wed 30 Nov 2005, 01:54    Post subject:  

Guest; what you've said makes perfect sense, I've not tried it yet, but it looks good.
MU; I had to stare at it for about 10 mins. before I saw what was going on.
The "s/^.*=/" I got, but it took awhile till I saw how that was being erased by "//", leaving only the last part.
It'll take awhile till the chaos logic has realigned my brain synapses from the M$ world, MANY THANKS.
Back to top
View user's profile Send private message 
rarsa


Joined: 29 May 2005
Posts: 3053
Location: Kitchener, Ontario, Canada

PostPosted: Wed 30 Nov 2005, 02:07    Post subject:  

Actually the easiest way to get the 'value' for all the name/value pairs is:
Code:
cut -d= -f2 /sbin/lanpup.cfg


Or if you want just for one value (assuming that the name starts at the begining of the line)
Code:
grep "^SERV=" /sbin/lanpup.cfg | cut -d= -f2


Explanation

cut : splits an input line into fields
-d : specifies the delimiter. In this case "="
-f : specifies the field number. In this case the second field.
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Wed 30 Nov 2005, 02:20    Post subject:  

rarsa; again I had to stare at it, but I understand what's happening, cut is like VBs InStr$ command, sort of.
The first example I want to know how to retreve each separate value if all of them are gotten at once.
Back to top
View user's profile Send private message 
rarsa


Joined: 29 May 2005
Posts: 3053
Location: Kitchener, Ontario, Canada

PostPosted: Wed 30 Nov 2005, 12:03    Post subject:  

I went to bed yesterday thinking that we are getting it all wrong.

If you need to know the values of all those variables from within a script, Why not executing the cfg file as if it was a script? e.g.:
Code:
sh /sbin/lanpup.cfg
echo $SERV
echo $SMBHOME
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Wed 30 Nov 2005, 22:43    Post subject:  

rarsa; I knew there had to be an even easier way to do it... you found it.
I took guest's suggestion & put it in a loop, & that was the tightest code till your idea, how simple!
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Thu 01 Dec 2005, 00:33    Post subject: How to create a shell script  

We could do with a ScriptTutorials page on the wiki
incorporating or cutting / pasting from here:

http://puppylinux.org/wikka/AzBash
http://puppylinux.org/wikka/AshSh

with links such as
http://www.grymoire.com/Unix/Sed.html

and a wink video on "How to create a shell script"

Wink

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
Location: Arizona, U.S.A.

PostPosted: Thu 01 Dec 2005, 18:05    Post subject:  

I'd help, but I'm afraid I'd get the info wrong somehow, I still need too much help myself, maybe in the future I could do a few things like that.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [10 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0590s ][ Queries: 11 (0.0043s) ][ GZIP on ]