The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 07-17-2008
TinWalrus TinWalrus is offline
Registered User
  
 

Join Date: May 2007
Posts: 35
Ifs

you can manipulate the IFS (internal field separator) - as an example - given that go.dat contains the lines with spaces

# create the array, without manipulating IFS, spaces will break the array
#
set -A lines $(cat go.dat)
for line in "${lines[@]}"; do
echo "'$line'"
done

# create the array, but first change the IFS (set it back - very important)
# after the array is set
#
oIFS=$IFS
IFS=${IFS##?}
set -A lines $(cat go.dat)
IFS=$oIFS

for line in "${lines[@]}"; do
echo "'$line'"
done


### go.dat ###
idno a|PRODUCT|Name|street town postcode|etc|etc|etc|etc
idno b|PRODUCT|Name|street town postcode|etc|etc|etc|etc
idno c|PRODUCT|Name|street town postcode|etc|etc|etc|etc

### end go.dat ###


i realize that does not help your problem (darkness fish already answered) so i thought i would throw my .02 in about IFS - since i have been bitten by that in the past - and it comes in handy quite often