|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello people
![]() i have been stuck for over a day now on this one bit and i hope someone out there can me. i have a c shell script and basically i want to get the following output into a variable for use further on in the script.. the output i want is generated from the below command echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' obviously if there is a better way then please advise but i need to remove the last five characters from the ORACLE SID environment.. kind regards Dal |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
DalUK wrote:
> Hello people ![]() > > i have been stuck for over a day now on this one bit and i hope > someone out there can me. > > i have a c shell script and basically i want to get the following > output into a variable for use further on in the script.. > > the output i want is generated from the below command > > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > > > obviously if there is a better way then please advise but i need to > remove the last five characters from the ORACLE SID environment.. > > kind regards > Dal > Posix shells: echo "${ORACLE_SID%?????}" All shells: expr x"$ORACLE_SID" : x"\(.....\)" -- Michael Tosch @ hp : com |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
DalUK wrote:
> Hello people ![]() > > i have been stuck for over a day now on this one bit and i hope > someone out there can me. > > i have a c shell script and basically i want to get the following > output into a variable for use further on in the script.. > > the output i want is generated from the below command > > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > > > obviously if there is a better way then please advise but i need to > remove the last five characters from the ORACLE SID environment.. > > kind regards > Dal > Posix shells: echo "${ORACLE_SID%?????}" All shells: expr x"$ORACLE_SID" : x"\(.....\)" -- Michael Tosch @ hp : com |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Michael Tosch wrote:
> DalUK wrote: >> Hello people ![]() >> >> i have been stuck for over a day now on this one bit and i hope >> someone out there can me. >> >> i have a c shell script and basically i want to get the following >> output into a variable for use further on in the script.. >> >> the output i want is generated from the below command >> >> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' >> >> >> obviously if there is a better way then please advise but i need to >> remove the last five characters from the ORACLE SID environment.. >> >> kind regards >> Dal >> > > Posix shells: > > echo "${ORACLE_SID%?????}" > > All shells: > > expr x"$ORACLE_SID" : x"\(.....\)" Oops, the latter should be expr x"$ORACLE_SID" : x"\(.*\)....." -- Michael Tosch @ hp : com |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Michael Tosch wrote:
> DalUK wrote: >> Hello people ![]() >> >> i have been stuck for over a day now on this one bit and i hope >> someone out there can me. >> >> i have a c shell script and basically i want to get the following >> output into a variable for use further on in the script.. >> >> the output i want is generated from the below command >> >> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' >> >> >> obviously if there is a better way then please advise but i need to >> remove the last five characters from the ORACLE SID environment.. >> >> kind regards >> Dal >> > > Posix shells: > > echo "${ORACLE_SID%?????}" > > All shells: > > expr x"$ORACLE_SID" : x"\(.....\)" Oops, the latter should be expr x"$ORACLE_SID" : x"\(.*\)....." -- Michael Tosch @ hp : com |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
DalUK <msn.dal@gmail.com> writes:
> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' echo $ORACLE_SID | sed 's/.....$//s' |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
DalUK <msn.dal@gmail.com> writes:
> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' echo $ORACLE_SID | sed 's/.....$//s' |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote: > DalUK wrote: > > Hello people ![]() > > > i have been stuck for over a day now on this one bit and i hope > > someone out there can me. > > > i have a c shell script and basically i want to get the following > > output into a variable for use further on in the script.. > > > the output i want is generated from the below command > > > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > > > obviously if there is a better way then please advise but i need to > > remove the last five characters from the ORACLE SID environment.. > > > kind regards > > Dal > > Posix shells: > > echo "${ORACLE_SID%?????}" > > All shells: > > expr x"$ORACLE_SID" : x"\(.....\)" > > -- > Michael Tosch @ hp : com- Hide quoted text - > > - Show quoted text - Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what i had however i still cannot seem to get the write syntax in cshell to get that output into a variable, is this something you would be able to assist me with thanks Dal |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote: > DalUK wrote: > > Hello people ![]() > > > i have been stuck for over a day now on this one bit and i hope > > someone out there can me. > > > i have a c shell script and basically i want to get the following > > output into a variable for use further on in the script.. > > > the output i want is generated from the below command > > > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > > > obviously if there is a better way then please advise but i need to > > remove the last five characters from the ORACLE SID environment.. > > > kind regards > > Dal > > Posix shells: > > echo "${ORACLE_SID%?????}" > > All shells: > > expr x"$ORACLE_SID" : x"\(.....\)" > > -- > Michael Tosch @ hp : com- Hide quoted text - > > - Show quoted text - Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what i had however i still cannot seem to get the write syntax in cshell to get that output into a variable, is this something you would be able to assist me with thanks Dal |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
On Jul 31, 6:16 am, DalUK <msn....@gmail.com> wrote:
> Hello people ![]() > > i have been stuck for over a day now on this one bit and i hope > someone out there can me. > > i have a c shell script and basically i want to get the following > output into a variable for use further on in the script.. > > the output i want is generated from the below command > > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > > obviously if there is a better way then please advise but i need to > remove the last five characters from the ORACLE SID environment.. > > kind regards > Dal It sounds like you want to chop off the last five characters of $ORACLE_SID. First of all, you're not testing to see what happens if $ORACLE_SID is 5 characters or fewer. I'll assume you're doing that elsewhere. A simpler way to do what you want to do it this: echo $ORACLE_SID | sed 's/.....$//' In other words, replace five characters anchored to the end of the string with null. Note that unlike the awk technique you used, if ORACLE_SID has fewer than 5 characters, it isn't changed. You still have a problem if ORACLE_SID is exactly 5 characters. To get the result into another variable, use backticks -> `` setenv NEWVAR `echo $ORACLE_SID | sed 's/.....$//'` There are other ways of course, and I would recommend using a borne- shell like shell such as ksh or bash instead of csh. Good luck Ken Beer |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
DalUK wrote:
> On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se> > wrote: >> DalUK wrote: >>> Hello people ![]() >>> i have been stuck for over a day now on this one bit and i hope >>> someone out there can me. >>> i have a c shell script and basically i want to get the following >>> output into a variable for use further on in the script.. >>> the output i want is generated from the below command >>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' >>> obviously if there is a better way then please advise but i need to >>> remove the last five characters from the ORACLE SID environment.. >>> kind regards >>> Dal >> Posix shells: >> >> echo "${ORACLE_SID%?????}" >> >> All shells: >> >> expr x"$ORACLE_SID" : x"\(.....\)" >> >> -- >> Michael Tosch @ hp : com- Hide quoted text - >> >> - Show quoted text - > > > > Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what > i had however i still cannot seem to get the write syntax in c> shell to get that output into a variable, is this something you would > be able to assist me with > Posix shell: var=${ORACLE_SID%?????} echo "$var" C-shell: set var=`expr x"$ORACLE_SID" : x"\(.*\)....."` echo "$var" -- Michael Tosch @ hp : com |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On 2007-07-31, DalUK wrote:
> Hello people ![]() > > i have been stuck for over a day now on this one bit and i hope > someone out there can me. > > i have a c shell script and basically i want to get the following > output into a variable for use further on in the script.. > > the output i want is generated from the below command > > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > > > obviously if there is a better way then please advise but i need to > remove the last five characters from the ORACLE SID environment.. In a POSIX shell (bash, ksh, etc.), you can use parameter expansion: ORACLE_SID=${ORACLE_SID%?????} Csh is not recommended for scripting. -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
On 31 Jul, 17:38, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote: > DalUK wrote: > > On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se> > > wrote: > >> DalUK wrote: > >>> Hello people ![]() > >>> i have been stuck for over a day now on this one bit and i hope > >>> someone out there can me. > >>> i have a c shell script and basically i want to get the following > >>> output into a variable for use further on in the script.. > >>> the output i want is generated from the below command > >>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > >>> obviously if there is a better way then please advise but i need to > >>> remove the last five characters from the ORACLE SID environment.. > >>> kind regards > >>> Dal > >> Posix shells: > > >> echo "${ORACLE_SID%?????}" > > >> All shells: > > >> expr x"$ORACLE_SID" : x"\(.....\)" > > >> -- > >> Michael Tosch @ hp : com- Hide quoted text - > > >> - Show quoted text - > > > Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what > > i had however i still cannot seem to get the write syntax in c> > shell to get that output into a variable, is this something you would > > be able to assist me with > > Posix shell: > > var=${ORACLE_SID%?????} > echo "$var" > > C-shell: > > set var=`expr x"$ORACLE_SID" : x"\(.*\)....."` > echo "$var" > > -- > Michael Tosch @ hp : com- Hide quoted text - > > - Show quoted text - Thats the puppy thank you very very much... i can sleep tonightnow ;-) regards Dal |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
On 31 Jul, 17:38, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote: > DalUK wrote: > > On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se> > > wrote: > >> DalUK wrote: > >>> Hello people ![]() > >>> i have been stuck for over a day now on this one bit and i hope > >>> someone out there can me. > >>> i have a c shell script and basically i want to get the following > >>> output into a variable for use further on in the script.. > >>> the output i want is generated from the below command > >>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}' > >>> obviously if there is a better way then please advise but i need to > >>> remove the last five characters from the ORACLE SID environment.. > >>> kind regards > >>> Dal > >> Posix shells: > > >> echo "${ORACLE_SID%?????}" > > >> All shells: > > >> expr x"$ORACLE_SID" : x"\(.....\)" > > >> -- > >> Michael Tosch @ hp : com- Hide quoted text - > > >> - Show quoted text - > > > Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what > > i had however i still cannot seem to get the write syntax in c> > shell to get that output into a variable, is this something you would > > be able to assist me with > > Posix shell: > > var=${ORACLE_SID%?????} > echo "$var" > > C-shell: > > set var=`expr x"$ORACLE_SID" : x"\(.*\)....."` > echo "$var" > > -- > Michael Tosch @ hp : com- Hide quoted text - > > - Show quoted text - Thats the puppy thank you very very much... i can sleep tonightnow ;-) regards Dal |
|
![]() |
| Outils de la discussion | |
|
|