You are not logged in.

#1 2008-07-13 09:04:49

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

space in bash question

I am looking for a way to cut a string by finding a space in a line of text

example

The cat sat on the mat

I want The?

in a string

tried looking at awk sed [ cut -f 1  works!] but need some way to store outpur of a command in a string ? eval ?

ok ok I have searched but I am not getting the right thing and you dudes know what you are talking about :-)

MrG


Mr Green

Offline

#2 2008-07-13 09:20:35

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,394
Website

Re: space in bash question

well, sticking with cut:

sto="$(echo "The cat sat on the mat" | cut -f1 -d" ")"

will store "The" in sto or you can go

phrase="The cat sat on the mat"
sto=${phrase%% *}

See: http://cyborg.lug.md/?p=25

Online

#3 2008-07-13 09:47:36

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: space in bash question

thanks man lol..... :-)

I assume eval is the way to get command output in a string .....?

will check out the link

Last edited by Mr Green (2008-07-13 09:48:24)


Mr Green

Offline

#4 2008-07-13 10:40:36

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,394
Website

Re: space in bash question

If you are getting into bash scripting, I highly recommend the Advanced Bash-Scripting Guide (http://tldp.org/LDP/abs/html/).  It has taught me almost everything I know on the subject with supplements from google.

Online

#5 2008-07-13 10:50:21

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,896
Website

Re: space in bash question

cool thanks a lot :-)


Mr Green

Offline

Board footer

Powered by FluxBB