Storing string with space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Storing string with space
# 1  
Old 10-04-2007
Storing string with space

Hi all
I am trying this simple command:
a="abc abc"
echo $a

output is: abc abc
But expected output shoould be :abc abc
i.e spaces in real string are geting truncated to one space everytime.

Plz Help.
# 2  
Old 10-04-2007
Quote:
Originally Posted by rahul303
Hi all
I am trying this simple command:
a="abc abc"
echo $a

output is: abc abc
But expected output shoould be :abc abc
i.e spaces in real string are geting truncated to one space everytime.

Plz Help.
Wrap $a within double quotes i.e. "$a"
# 3  
Old 10-04-2007
Not working in script!

cat my_file | while read line
do
last=`echo $line | cut -c 3-`
echo "$last"
done

my_file:
1US8738297897918[space][space][space]0[space][space]0[space][space]0
1US8738297897918[space][space][space]0[space][space]0[space][space]0
1US8738297897918[space][space][space]0[space][space]0[space][space]0

Expected output:
8738297897918[space][space][space]0[space][space]0[space][space]0
8738297897918[space][space][space]0[space][space]0[space][space]0
8738297897918[space][space][space]0[space][space]0[space][space]0

Current Output:
8738297897918[space]0[space]0[space]0
8738297897918[space]0[space]0[space]0
8738297897918[space]0[space]0[space]0

Plz Help !
# 4  
Old 10-04-2007
The read command removes leading and traling Input Field Separators.
The echo command doesn't preserve multiple IFS between argument strings.
Code:
while IFS= read line
do 
   last=`echo "$line" | cut -c 3-`
   echo "$last"
done <my_file

Jean-Pierre.
# 5  
Old 10-04-2007
Thankssssssssssssss

It worked !
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding specific string in file and storing in another file

Text in input file is like this <title> <band height="21" isSplitAllowed="true" > <staticText> <reportElement x="1" y="1" width="313" height="20" key="staticText-1"/> <box></box> <textElement> <font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies

2. Shell Programming and Scripting

Awk: Storing string in array(triangular form)

I have a string like below. Now i want to split this string like below and put the value in the array using awk. I am able to do it using bash but getting no clue for doing it in awk O/P A=0 A=01 A=014 A=0143 A=01438 A=014387 A=0143876 A=01438765 A=014387650 ... (7 Replies)
Discussion started by: siramitsharma
7 Replies

3. Shell Programming and Scripting

Cutting a string and storing it in a variable

Hello I have a script: path=test1 echo "${path%?}" till this the program is successful in deleting hte last character i.e. "1" and displays an output --> test. After this how can i save this output to another variable. (2 Replies)
Discussion started by: Kishore920
2 Replies

4. Shell Programming and Scripting

String comparison with a space

Hello Gurus, I've searched enough to find what I wanted and finally ended up creating a thread. I'm in the process of coding something like below sed -n -e "s/.*\(successfully completed\).*/\1/p" xxx.log read status if ] then #sleep 3; echo "Export... (4 Replies)
Discussion started by: rajivan
4 Replies

5. Programming

Splitting string and storing in int

I have a string containing 2 integers separated by /, for example 12/8 or 8/6 am want to store the numbers in two integers. (3 Replies)
Discussion started by: kristinu
3 Replies

6. Shell Programming and Scripting

Extracting particular string in a file and storing matched string in output file

Hi , I have input file and i want to extract below strings <msisdn xmlns="">0492001956</ msisdn> => numaber inside brackets <resCode>3000</resCode> => 3000 needs to be extracted <resMessage>Request time getBalances_PSM.c(37): d out</resMessage></ns2:getBalancesResponse> => the word... (14 Replies)
Discussion started by: sushmab82
14 Replies

7. Shell Programming and Scripting

Storing string with space (urgent)

hi i have a file content like my_file: 1US8738297897918000 000 000 i used while IFS= read line do echo "$line" | grep '^\ then last=`echo "$line" | cut -c 3-20` echo "$last" fi done < $my_file but it is writing blank spaces into the o/p fie (1 Reply)
Discussion started by: Satyak
1 Replies

8. Shell Programming and Scripting

searching and storing unknown number of lines based on the string with a condition

Dear friends, Please help me to resolve the problem below, I have a file with following content: date of file creation : 12 feb 2007 ==================== = name : suresh = city :mumbai #this is a blank line = date : 1st Nov 2005 ==================== few lines of some text this... (7 Replies)
Discussion started by: swamymns
7 Replies

9. Shell Programming and Scripting

sed - searching for string and storing in variable

Hi I'm trying to find a way to search a text file for a specific string. I have a file which contains i.p. addresses and port numbers in the following format: 'ip="www.xxx.yyy.zzz"' 'port="xx""' I want to print only the parts between the double quotes for use in seperate variables,... (4 Replies)
Discussion started by: melias
4 Replies

10. Shell Programming and Scripting

Storing space delimited line in var with loop?

I have a script that converts a file into an html table. This script works fine for a 1 column table. However, I'm trying to do this for a multi-column table. My input file will look something like this: a b c d e f g h i My script basically works by taking in each line and putting that... (2 Replies)
Discussion started by: eltinator
2 Replies
Login or Register to Ask a Question