The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 03-17-2009
dariyoosh's Avatar
dariyoosh dariyoosh is offline
Registered User
  
 

Join Date: Mar 2009
Location: Iran (Tehran)
Posts: 44
Hello there,

As it was said, you really have to define a pattern/structure for your file including the exact field numbers where data is supposed to be modified or at least a group of specific values according to which the script has to search the file and to add what is missing.

Just for giving you a first idea, if the specific values are 441 and 442, then the following KornShell script will do the job


Code:
#!/bin/ksh

RESULT=""

while read LINE
do
    for ITERATOR in $LINE
    do
        if [[ $ITERATOR = "442"  ]]
        then
            RESULT="$RESULT 441 $ITERATOR"
        else
            RESULT="$RESULT $ITERATOR"
        fi
    done
    RESULT="$RESULT\n"
done < $1

print "$RESULT" > $1

So if there are several values, you can specify them in the for loop.

Yet, this works if and only if the delimiters in your file are the default values for IFS that is, \n \t and ' '.

Regards,