This will do the job

File starts from the line "#!/bin/bash

--- ---------------------------------------
#!/bin/bash
#----------------------------------------------------------------------------------
#AUTHOR: William Ampeh
#PURPOSE: Reads input from $1 (a file) and print output to $2 (another
file)
#---------------------------------------------------------------------------------

if [ $# -ne 2 ]
then
   echo ""; echo ""; echo "USAGE: $0 {input file} {ouput filename}"; echo
""
   echo "   EG: $0 infile.txt outfile.txt"; echo ""; echo ""; exit 1
fi

INFILE=$1; OUTFILE=$2
#.................... in case user switches order
..............................
[ -s $OUTFILE ] && { echo "ERROR: $OUTFILE already exists.  Remane or
delete it"; echo ""; exit 2; }
#................... keeping track of old file handlers
.........................
exec 4<&0   #save stdin handle, just a safety precaution in case you want
to
            #read input from keyboard somewhere in this script

exec 5<&1   #save stdout handle, just a safety precaution in case you want
to
            #write to screen somewhere in this script

exec 0< $INFILE       #opens $INFILE as file handle 0 (stdin)
exec 1> $OUTFILE      #opens $OUTFILE as file handle 1 (stdout)

while read cell1 cell2 cell3 rest_of_line
do
   echo "column2 = $cell2    -- rest of line = $rest_of_line "
#say

   #........ do some more manipulations
done

#........................... restore old file handlers
.........................
exec 0<&4; exec 1<&5

echo ""; echo ""; echo "             DONE"
exit 0

#--------------------------------------------------------------
# TRY THIS ON THE FOLLOWING INPUT FILE
#l1_c1 l1_c2 l1_c3 l1_c4 l1_c5
#l2_c1 l2_c2 l2_c3 l2_c4 l2_c5
#l3_c1 l3_c2 l3_c3 l3_c4 l3_c5
#l4_c1 l4_c2 l4_c3 l4_c4 l4_c5
#l5_c1 l2_c2 l2_c3 l2_c4 l2_c5
#l6_c1 l6_c2 l6_c3 l6_c4 l6_c5


#The output will be:
#column2 = l1_c2    -- rest of line = l1_c4 l1_c5
#column2 = l2_c2    -- rest of line = l2_c4 l2_c5
#column2 = l3_c2    -- rest of line = l3_c4 l3_c5
#column2 = l4_c2    -- rest of line = l4_c4 l4_c5
#column2 = l2_c2    -- rest of line = l2_c4 l2_c5
#column2 = l6_c2    -- rest of line = l6_c4 l6_c5

__________________

William Ampeh (x3939)
Federal Reserve Board


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to