Truncate and Append in unix shell scripting

Hi All,

I have a long log file (abc.log) which contains large volume of data that need to be inserted into the database as clob.

I am having problem in inserting the long log file into the clob field if the cahracters in the file exceeds. So iwould like to truncate the file upto 32767 characters and append a string at last "Log file to large to view go to server".

Please advice, any links or samples appriciated.

Thanks
Raj

You could use head command (has a byte count option...)

Are there lines of output in the log so the file can be read by awk?

awk ' BEGIN {rec="" }
        { if length(rec)> 32767) {next};
           rec=sprintf( "%s\n", $0)
        }
        END { if (length(rec) > 32767) {rec=substr(rec,1,32767)}
                 print rec, "Log file to large to view go to server"
               }'   input_logfile   > newfile

Another way :

{ 
  dd count=1 bs=32767 if=input-file 2>/dev/null
  echo "\nLog file to large to view go to server"
} > output_file

Jean-Pierre.