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
Retaining spaces between words RcR Shell Programming and Scripting 7 07-29-2008 11:29 PM
Retaining Spaces within a word RcR UNIX for Dummies Questions & Answers 0 09-09-2007 08:19 PM
Redirecting OUTPUT Chanakya.m Shell Programming and Scripting 1 08-13-2007 01:27 PM
redirecting the output of aspell leekb UNIX for Advanced & Expert Users 6 07-10-2006 02:50 AM
Redirecting output to TCP port mscomms UNIX for Dummies Questions & Answers 1 09-30-2003 07:51 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2007
Registered User
 

Join Date: Jun 2006
Posts: 2
Retaining Spaces while redirecting output

I need to merge data from more than one file and I am using

while read line_record
do
field1=`echo $line_record | awk -F "," '{ print $1 }'`
echo $line_record >> $outFile

if [ "$field1" = "qualifier1" ]
then
while read new_linerec
do
echo $new_linerec >> $outFile
done < $File2
done < $File1

File 1 and File 2 contains indented data in it and after executing this code; the new file outFile contains all records with truncated spaces, tabs, etc...

How can I retain the original format of data when copying it to output ?

Last edited by skrakesh; 01-30-2007 at 04:23 PM. Reason: Reformatting issue
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-30-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,502
quotes...see the man page for your shell to understand the behaviour of echo and why it does this, and the section on quoting for why this makes a dfference.
Reply With Quote
  #3 (permalink)  
Old 01-31-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,199
Quoting is just a part of the problem.
The read statement removes leading and trailing spaces (for standard Input Field Separator) :
Code:
$ cat in.dat
1111111
    55555555
       8888888
 2222222
1111111
$ cat in.ksh
while read line
do
   echo "$line"
done < in.dat
$ in.ksh
1111111
55555555
8888888
2222222
1111111
$
The solution is to clear or to force the Input Field Separator to another value.
Code:
$ cat in.ksh
while IFS= read line
do
   echo "$line"
done < in.dat
$ in.ksh
1111111
    55555555
       8888888
 2222222
1111111
$

Jean-Pierre.
Reply With Quote
  #4 (permalink)  
Old 01-31-2007
Registered User
 

Join Date: Jun 2006
Posts: 2
Thank You!

Thanks, Jean-Pierre.

Your solution did work.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:23 AM.


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 Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0