I have a ksh script which gathers data from a file. I need to find a way to direct the output to a new file. The code looks something like this:
DUP_FILE=`touch /export/.../.../dup_social_$1`
while (($# > 0 ))
do
# Make sure the file exists
if [[ ! -f $1 ]]
then
print "$1: does not exist or not accessible \n"
else
#open the file for input
exec 0<$1
while read LINE
do
# Store Social Security numbers to SOCIAL1 and SOCIAL2
SOCIAL1=`echo "$LINE" | awk '{ print substr ($0, 105, 9) }'`
SOCIAL2=`echo "$LINE" | awk '{ print substr ($0, 212, 9) }'`
if [ "$SOCIAL1" = "$SOCIAL2" ] ; then
print "$LINE" >> ${DUP_FILE}
fi
...
...
The output is sent to the screen, but not to $DUP_FILE. What am I missing to get the output to go to $DUP_FILE?
Thanks for the reply. I solved this problem with the following:
DUP_FILE="/export/.../.../dup_social_$1"
while (($# > 0 ))
do
# Make sure the file exists
if [[ ! -f $1 ]]
then
print "$1: does not exist or not accessible \n"
else
#open the file for input
exec 3>$DUP_FILE
exec 0<$1
while read LINE
do
# Store Social Security numbers to SOCIAL1 and SOCIAL2
SOCIAL1=`echo "$LINE" | awk '{ print substr ($0, 105, 9) }'`
SOCIAL2=`echo "$LINE" | awk '{ print substr ($0, 212, 9) }'`
if [ "$SOCIAL1" = "$SOCIAL2" ] ; then
print -u3 "$LINE"
fi
...
...
# Close the open file descriptor 3
exec 3>&-
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.