The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


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


Other UNIX.COM Threads 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 12: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 Search this Thread Display Modes
  #1 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 11
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 (permalink)  
Old 10-04-2007
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,626
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 11
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 (permalink)  
Old 10-04-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,072
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 11
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Thankssssssssssssss

It worked !
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 03:12 PM.


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

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102