String concate problem

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String concate problem
# 1  
Old 09-24-2010
String concate problem

Hello there,

I am facing the following problem in string concate.

I am returning a sql column value to a shell script variable .
Now when I am trying to concate the variable with another string (string appears first)
I am getting a space between the two concate.

Example p is the shell variable which takes the value of a column value say 9666
now when I try q = '+'$p I am getting + 9666 (a space between + and 966) instead of +9666

Please help me to resolve the situation

I think there is new line appending because when I run the command
echo "$q"|sed 's/ //g'
I found the o/p as

Last edited by Pratik4891; 09-24-2010 at 09:40 AM..
# 2  
Old 09-24-2010
This should work with any number of leading or trailing spaces.

q='+'$(echo $p)

# 3  
Old 09-24-2010
Thanks a lot Smilie
It works!!!!!!!!!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concate a string in awk

Hello Community, i have a litte Problem with concating a string in an awk command. val_arr=( $( cat myfile | awk ' NR==1 { name=$2} NR==3 { dateformat=$9 OFS $6 OFS $8 OFS $7 OFS $10} NR==4 { length=$8} NR==5 { progress=int($3) } END{print name,dateformat,length,progress}; ... (6 Replies)
Discussion started by: demonking
6 Replies

2. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

3. Shell Programming and Scripting

Problem in comparing 2 files string by string

Hi Champs, I am a newbie to unix world, and I am trying to built a script which seems to be far tough to be done alone by me..... " I am having a raw csv file which contains around 50 fields..." From that file I have to grep 2 fields "A" and "B"....field "A" is to be aligned vertically... (11 Replies)
Discussion started by: jitendra.pat04
11 Replies

4. Shell Programming and Scripting

Runaway String Problem

Database.txt John:30:40 echo -n "New Title Please :" read NewTitle awk -F":" 'OFS = ":"{ $1 = "'$NewTitle'" ; print $0 } ' Database.txt> Database2.txt mv Database2.txt Database.txt what this does, is that when i input something into $NewTitle, it will update $1 which is "John" into... (3 Replies)
Discussion started by: gregarion
3 Replies

5. Solaris

concate / stripes in solaris 8 to solaris 10

We did live upgrade from solaris 8 (primary boot environment) to 10 . Switching to alternative boot environment in solaris 10 succeeded but it gave disk error for our concat , strips & mirrors for existing mount points which are already in use . It advised to run fsck on these device. So I... (6 Replies)
Discussion started by: Hitesh Shah
6 Replies

6. UNIX for Dummies Questions & Answers

using nawk to concate the fields

I have the the following question: # cat report.lis | nawk -F: '{ if($0 ~ "^BE NO:") print "report_"$2".lis"}' :confused: .lisrt_ 111 .lisrt_ 111 .lisrt_ 222 .lisrt_ 222 .lisrt_ 333 .lisrt_ 333 # cat report.lis | nawk -F: '{ if($0 ~ "^BE NO:") print "report_" $2}' report_ 111 report_... (2 Replies)
Discussion started by: raychu65
2 Replies

7. Shell Programming and Scripting

concate the record

how i can bring this file into three records in my sample text file there are thre records new records always start with Data File ================================================== samle file ================================================= Data File:... (7 Replies)
Discussion started by: aboorkuma
7 Replies

8. UNIX for Dummies Questions & Answers

problem with if -z string

someone please help me out here. i am not a newbie. i just haven't posted on this board in years. i'm talking at least two and a half years. My last user name was TRUEST. i couldn't log into this name because i forgot my password and my aol email address has long been deleted. anyway, i'm... (1 Reply)
Discussion started by: Terrible
1 Replies

9. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

10. Shell Programming and Scripting

Concate all lines into one.

I have a file with 1000 records and I have to produce another file with 1 line which is a concatentation of all these records. Please help. (1 Reply)
Discussion started by: oracle8
1 Replies
Login or Register to Ask a Question

Featured Tech Videos