The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching and storing unknown number of lines based on the string with a condition swamymns Shell Programming and Scripting 7 05-12-2008 10:02 PM
how to seperate space in a string kittusri9 Shell Programming and Scripting 5 05-08-2008 03:43 AM
sed - searching for string and storing in variable melias Shell Programming and Scripting 4 04-12-2008 11:57 AM
Remove unregconized space from a string Ricole UNIX for Dummies Questions & Answers 3 02-29-2008 01:35 AM
Storing space delimited line in var with loop? eltinator Shell Programming and Scripting 2 08-23-2007 10:09 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 11
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.
Reply With Quote
Forum Sponsor
  #2  
Old 10-04-2007
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Quote:
Originally Posted by rahul303 View Post
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"
Reply With Quote
  #3  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 11
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 !
Reply With Quote
  #4  
Old 10-04-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
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.
Reply With Quote
  #5  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 11
Thankssssssssssssss

It worked !
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0