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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to compare null and space using single if condition jayakumarrt UNIX for Dummies Questions & Answers 3 05-16-2008 06:13 AM
Replace blank spaces by single tab, and right alignment Jae Shell Programming and Scripting 1 08-08-2007 11:58 PM
how to read double consecutive space in filename for bash shell james_falco UNIX for Dummies Questions & Answers 1 07-17-2007 05:32 PM
replacing single space in argument convenientstore Shell Programming and Scripting 7 04-25-2007 02:02 PM
single input shell script? quipy Shell Programming and Scripting 1 10-03-2002 09:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-31-2007
NinersFan NinersFan is offline
Registered User
  
 

Join Date: Aug 2007
Location: Toronto
Posts: 3
Consecutive spaces within input being converted to single space

I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"):

e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA

When I read this record and either echo/print to screen or write to output, the 2 spaces get converted to a single space. I need to keep all spaces intact when writing to output.

Here's a snippet of code I'm using. I'm attempting to load a series of records into an array with the purpose of performing logic on the contents and then outputting to several different output(s):

exec 3<$1 # Open input
exec 4>$1.out # Open output
let CNF_REC_CNT=CNF_REC_CNT+1
read -u3 REC_BUF[CNF_REC_CNT]
print "Buffer is : "${REC_BUF[CNF_REC_CNT]}""

How do I get around this?
  #2 (permalink)  
Old 08-31-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
try:

Code:
IFS="" && read  REC_BUF[CNF_REC_CNT]
IFS=" "

  #3 (permalink)  
Old 08-31-2007
NinersFan NinersFan is offline
Registered User
  
 

Join Date: Aug 2007
Location: Toronto
Posts: 3
Still doesn't work. Thx for trying. Getting same results.
  #4 (permalink)  
Old 08-31-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
You need to put the variable inside single quotes when you print it. You think you did this but you didn't:

print "Buffer is : "${REC_BUF[CNF_REC_CNT]}""

First quoted string:"Buffer is : "
Unquoted string: ${REC_BUF[CNF_REC_CNT]}
Second quoted string: ""

Maybe you wanted:
print "Buffer is : \"${REC_BUF[CNF_REC_CNT]}\""
which is now a single quoted string.
  #5 (permalink)  
Old 09-04-2007
NinersFan NinersFan is offline
Registered User
  
 

Join Date: Aug 2007
Location: Toronto
Posts: 3
That may have been a typo on my part. My program does write to output ok except for the fact that the double space comes out as a single space.

I'm going to ditch using the 'read' command and try using a combination of cat, grep and awk to rip through the file. If I do a :

REC_BUF=`grep '^' $1`

and then output to screen, the 2 spaces appear. Therefore I know it's a 'read' specific feature.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB 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 -4. The time now is 03:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0