![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| redirect output to a file name | csecnarf | UNIX for Dummies Questions & Answers | 7 | 06-16-2008 04:45 AM |
| redirect output to log file | kalyanraj | Shell Programming and Scripting | 2 | 06-07-2007 01:40 AM |
| redirect output to file | xadamz23 | Shell Programming and Scripting | 4 | 06-29-2006 12:20 PM |
| How to redirect debug statement to file? | redlotus72 | UNIX for Dummies Questions & Answers | 1 | 08-02-2005 09:26 PM |
| redirect output to file? | slackware | Shell Programming and Scripting | 1 | 09-12-2003 03:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Redirect output of print statement to file
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:Code:
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? Last edited by vidyadhar85; 08-27-2009 at 04:20 PM.. Reason: code tag added |
|
||||
|
Thanks for the reply. I solved this problem with the following: Code:
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>&-
Last edited by vgersh99; 08-27-2009 at 05:23 PM.. Reason: code tags, PLEASE! |
|
||||
|
Quote:
Try: Code:
DUP_FILE="/export/.../.../dup_social_$1" ---------- Post updated at 09:32 PM ---------- Previous update was at 09:25 PM ---------- Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|