Wednesday, 15 January 2014

scripting - getting a column of a specific line in bash -



scripting - getting a column of a specific line in bash -

i have command :

id=$(xl list|egrep $name| tr -s ' ' | cutting -d ' ' -f 2)

which xl list output this:

name id mem vcpus state time(s) domain-0 0 5923 8 r----- 4266.0 new_redhat9-clone 3 1027 1 r----- 1019.6 new_redhat9 4 1027 1 -b---- 40.1

actually want id of given name. works when name=new_redhat9-clone (it returns 3) doesnt work when name=new_redhat9 (it returns: 3 4!!!!). wrong?!!!

grep searches string pattern match. egrep new_redhat9 match "new_redhat9" , "new_redhat9-clone". seek add together whiteespace (or \t) after pattern, rewrite this

id=$(xl list|egrep 'new_redhat9 '| tr -s ' ' | cutting -d ' ' -f 2)

bash scripting command

No comments:

Post a Comment