How to trim space in output variable ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to trim space in output variable ?
# 1  
Old 06-10-2005
How to trim space in output variable ?

Hi ,
I have a code like this:

uid=scott
password=tiger
database=db01

cat >runid_val.sql<<-EOA
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SELECT trim(runid_seq.nextval) FROM dual;
EXIT
EOA
echo `cat runid_val.sql`
V_RUNID=`sqlplus -s $uid/$password@$database @runid_val.sql`
echo V_RUNID:$V_RUNID

rundsjob -param runid=$V_RUNID
exit

I need to use this variable value in next command as shown above but its adding a space to out variable:
rundsjob -param runid= 26
and I wants like this: rundsjob -param runid=26

CAN ANYONE TELL ME HOW TO REMOVE THE SPACE in $V_RUNID?

Thanks & Regards,
VJ
# 2  
Old 06-10-2005
Code:
$ V_RUNID="rundsjob -param runid= 26"
$ V_RUNID=`echo "${V_RUNID}" | sed 's/^\([^=]*=\) \(.*\)$/\1\2/'`
$ echo "${V_RUNID}"
rundsjob -param runid=26
$

Cheers
ZB
# 3  
Old 06-10-2005
typeset -i V_RUNID=`sqlplus etc...`
# 4  
Old 06-10-2005
MySQL

V_RUNID=`echo $V_RUNID | tr -d ' '`
# 5  
Old 06-10-2005
V_RUNID=`echo $V_RUNID`
# 6  
Old 06-12-2005
Quote:
Originally Posted by RishiPahuja
V_RUNID=`echo $V_RUNID | tr -d ' '`
But the OP only wants to delete the space on the RHS of the = symbol, not all spaces....
Quote:
Originally Posted by vj_76
rundsjob -param runid= 26
and I wants like this: rundsjob -param runid=26
My sed post above solves this issue....

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gawk --- produce the output in pattern space instead of END space

hi, I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST... (2 Replies)
Discussion started by: busyboy
2 Replies

2. Shell Programming and Scripting

Trim Space

In Shell, I have output of a unix command as test1 test2015 but I want it as test1 test2015 can anyone help me out. Use code tags, thanks. (3 Replies)
Discussion started by: OscarS
3 Replies

3. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

4. Shell Programming and Scripting

Trim sed output & assign to variable

Hi, I have the following command that parses an xml file to read a node <port>'s value. Hoever the output comes with spaces. My requirement is to trim the spaces around the value and assign to a variable. sed -n 's|<port>\(.*\)</port>|\1|p' ../cfg.xml How do I go about it? (6 Replies)
Discussion started by: sai2013
6 Replies

5. Shell Programming and Scripting

awk - trim white space from a field / variable

Hi, Consider the data (FS = |): 1| England |end 2| New Zealand |end 3|Australia|end 4| Some Made Up Country |end 5| West Indies|end I want the output to be (i.e. without the leading and trailing white space from $2) England New Zealand Australia Some Made Up Country West... (4 Replies)
Discussion started by: Storms
4 Replies

6. Shell Programming and Scripting

trim spaces in unix for variable

HI Guys I have written a script using awk to split a file based on some identifier and renaming the file based on two values from specific length. ts a fixed width file. When I am trying to fetch the values a = substr($0,11,10) b = substr($0,21,5); i am getting spaces in a and b values .... (6 Replies)
Discussion started by: manish8484
6 Replies

7. Shell Programming and Scripting

How to trim variable in linux?

Hi guys , I m developing a script in linux.but getting confused about how would i trim my variable if there is any space. for example. I m storing value in a variable named MACHINE_NAME if MACHINE_NAME=<space><space><space>ABCDF<space><space> How would i trim it to have my MACHINE_NAME=ABCDF... (5 Replies)
Discussion started by: pinga123
5 Replies

8. Shell Programming and Scripting

Using Variable With Space In It?

Hey , I'm new to Bash and am having trouble with writing a script. I have a variable and want to use it to create a tar file, but, I am having problems. Can anyone tell me what I'm doing wrong? filestr=`date "+%y-%m-%d %H.%M.%S"`.tar tar -cvf $filestr test.txt So, basically,... (3 Replies)
Discussion started by: beefeater267
3 Replies

9. Programming

How to trim the white space around a string in C program

I am coding a C program to read a plain text file. There are a lot of blank fields or a string with white spaces. I want to know is there such a function called trim() in C to clean the white space around a string? Or some other way can do this efficiently? Thanks. (18 Replies)
Discussion started by: hxm1303
18 Replies

10. Shell Programming and Scripting

how to merge two variable in one variable with space between them?

Dear all I had two separate variable. Now i want to make them merge into one new variable with space between them. Kindly suggest me. var1=dec 15 var2=10 i want var3=dec 15 10 My main aim is as below: op of date command: >date >Sat Dec 15 10:17:35 IST 2007 i want only Dec... (2 Replies)
Discussion started by: jaydeep_sadaria
2 Replies
Login or Register to Ask a Question