Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

read command

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-25-2008
COD COD is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 28 April 2008, 6:53 AM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
read command

I have file which is space filled likE below
Quote:
ABC8457573759||||||||||5565656|||||||||||564645645646
Note: here spaces are replaced by |.
When I use read command to read this file all the spaces are truncated only the default space is not removed. The output is
Quote:
ABC8457573759||5565656||564645645646
Note: here spaces are replaced by |.

Can this default truncation be override?
Sponsored Links
    #2  
Old Unix and Linux 04-25-2008
grial's Unix or Linux Image
grial grial is offline Forum Advisor  
El UNIX es como un toro
 
Join Date: Jun 2006
Last Activity: 1 December 2008, 8:39 AM EST
Location: Madrid (Spain)
Posts: 531
Thanks: 0
Thanked 1 Time in 1 Post
I assume you are storing each line of the file in a variable. In that case, use double quotes:


Code:
MYVARIABLE="ABC8457573759             5565656           564645645646"
echo "$MYVARIABLE"

Regards.
Sponsored Links
    #3  
Old Unix and Linux 04-25-2008
COD COD is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 28 April 2008, 6:53 AM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
What about this line:
Quote:
MYVARIABLE="ABC8457573759|||||||||5565656||||||||||||||||||564645645646||||||||||||"
echo "$MYVARIABLE"
Will it work?
    #4  
Old Unix and Linux 04-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts
Try it. Your definition of "work" might be more complex than we can guess.
Sponsored Links
    #5  
Old Unix and Linux 04-26-2008
COD COD is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 28 April 2008, 6:53 AM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Nope, its doesn't. The trailing and preceeding spaces are truncated. But if
Quote:
IFS
is set to something like
Quote:
IFS="$"
then the preceeding and trailing spaces can also be taken into account.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read command sharath24 Shell Programming and Scripting 1 08-19-2011 04:50 PM
read command - using output from command substitution ProGrammar UNIX for Dummies Questions & Answers 2 09-15-2010 08:25 PM
Read command Aswex UNIX for Dummies Questions & Answers 2 05-17-2010 08:45 AM
read command djehresmann Shell Programming and Scripting 2 03-04-2010 04:07 PM
read command in while avi.skynet Shell Programming and Scripting 7 02-02-2009 01:43 PM



All times are GMT -4. The time now is 11:43 AM.