Retaining Spaces while redirecting output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retaining Spaces while redirecting output
# 1  
Old 01-30-2007
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 08:23 PM.. Reason: Reformatting issue
# 2  
Old 01-30-2007
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.
# 3  
Old 01-31-2007
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.
# 4  
Old 01-31-2007
Thank You!

Thanks, Jean-Pierre.

Your solution did work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting output using if with awk

I have this line were I am selecting some fields from one file and creating a new file for the selected data. awk -F "\"*,\"*" '{print $1"," $2}' folderone/list.txt > folderone/qlist.txt This works, but then from this new file I want it to create a new file where it separates data: $2 >5 it... (2 Replies)
Discussion started by: rluna
2 Replies

2. Shell Programming and Scripting

Redirecting the output

For example, if we run the below command, symcfg list -thin -pool , results in an output most of the times and if the out is generated i'm able to redirect the output to a file. but sometimes it doesnt result any output and even though the output is being redirected, i can see "No Thin Pools "... (2 Replies)
Discussion started by: web2moha
2 Replies

3. Shell Programming and Scripting

redirecting output using if-then-else in awk

I am trying to filter records based on number of "|", delimiter in my application. If number of "|" is greater than 14 its a bad record, else its a good record. I have to redirect output to two different files based on the if-then-else evaluation in AWK. if number of “|” in file_0 > 14 ... (2 Replies)
Discussion started by: siteregsam
2 Replies

4. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

5. UNIX for Dummies Questions & Answers

redirecting output retaining the input

Hi Guys, I am trying to redirect output from a file to another file while retaining the contents of the input file. For ex: cat /tmp/Out1.cfg > test.txt Now, test.txt would contain the value of Out1.cfg.,ie say for ex "12" What i require is to have the value as "/tmp/Out1.cfg 12" in the... (2 Replies)
Discussion started by: kiran1112
2 Replies

6. Shell Programming and Scripting

help redirecting output from mailbot

Hello...I'm having problems redirecting output from a script from a mailbot. It is a perl script that has the email sent to op_shipper piped into it. I am receiving the email with sendmail and here is what my alias looks like for the script am I having problems with in /etc/aliases: ... (3 Replies)
Discussion started by: kuliksco
3 Replies

7. UNIX for Dummies Questions & Answers

Redirecting 'find' output...

Hi all, why does one version of this command work but not the other? - This file already exists with 644 mod permissions - I am logged in as d269836, no su rights. - Box is 'SunOS' running bash I think; but runs ksh scripts OK. This one works: find /users/d269836 -type f -name "*.txt"... (6 Replies)
Discussion started by: dan-e
6 Replies

8. Shell Programming and Scripting

Retaining spaces between words

Retaining Spaces within a word -------------------------------------------------------------------------------- Hi Experts, I have a 2 GB flat file which have unicode field, some of them are blanks and its size is 4000 character. In the existing system SED command removes the spaces.... (7 Replies)
Discussion started by: RcR
7 Replies

9. UNIX for Dummies Questions & Answers

Retaining Spaces within a word

Hi Experts, I have a 2 GB flat file which have unicode field, some of them are blanks and its size is 4000 character. In the existing system SED command removes the spaces. Because of this field itself....it is taking almost three days to complete the file processing. I removed sed and... (0 Replies)
Discussion started by: RcR
0 Replies

10. Shell Programming and Scripting

Redirecting OUTPUT

Hi, I want to move the output of a command/script to a file as well as to to be displayed on stdout. Can anybody help me in this. Thanks in advace .. -Chanakya M (1 Reply)
Discussion started by: Chanakya.m
1 Replies
Login or Register to Ask a Question