Results 1 to 3 of 3
Hi all,
I am new to linux shell script and I am currently facing a strange problem. Currently I am working on , in which I have a string and ...
- 09-20-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 7
Problem with string append
Hi all,
I am new to linux shell script and I am currently facing a strange problem. Currently I am working on , in which I have a string and I have to parse it to a specific string.
My problem is as like below.
echo $str1
# data1_data2_data3_data4 /. this string I have got from substring of main string
# now what I want to do is
str2="dt5_dt6.pdf"
a=$str1"_"$str2
echo $a
# that should print data1_data2_data3_data4_dt5_dt6.pdf but instead it prints like below "_dt4_dt6.pdfdata3_data4"
# in short it replaces str1's data with the str2's data from starting of str1
Please help me to solve this strange problem
Thanks in advance
- 09-20-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
ok, here's to try:
1. make a "str0" that contains and underscore '_'
2. paste -d " " str1 str0 str2 >str3
3. tr -d " " <str3 >str4
4. then str4 should be what you wantthe sun is new every day (heraclitus)
- 09-21-2010 #3Just Joined!
- Join Date
- Sep 2010
- Posts
- 7
Thanks for replying..
I have tried your code but it gives me following error
$str3: ambiguous redirect
I am copying my code here,
echo "sub Final 0 :" $PDFNM // prints "data1_data2_data3_data4"
echo "PI :" $PI // prints "dt5_dt6.pdf"
str0="_"
str3=""
str4=""
-d " " $PDFNM $str0 $PI >$str3 //gives error @ this line & below line
tr -d " " <$str3 >$str4
echo $str4
I might be wrong in syntax, as I am totally new in shell scripts...Please help me solve this issue
Thanks again


Reply With Quote