Storing string with space


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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  
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  
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  
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  
Thankssssssssssssss

It worked !
Smilie
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #408
Difficulty: Medium
The Cygwin distribution contains thousands of packages from the Open Source world including most GNU tools, many BSD tools, an X server and a full set of X applications.
True or False?

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

Comparing string's with space

How can i comparing string's whith blank spaces? I have this problem: DIF1="STRING 1212" DIF2="STRING 1212" if then echo "Differents" else echo "Equals" fi Error: 1212}: unknown test operator (3 Replies)
Discussion started by: Xedrox
3 Replies

4. 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

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

Featured Tech Videos