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 24 Jul 2014, 21:49
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 Posts_count  
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5009
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."

Edited_time_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: 13642
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_website 
sunburnt


Joined: 08 Jun 2005
Posts: 5009
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_website 
sunburnt


Joined: 08 Jun 2005
Posts: 5009
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_website 
sunburnt


Joined: 08 Jun 2005
Posts: 5009
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_website 
sunburnt


Joined: 08 Jun 2005
Posts: 5009
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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