Truncate and Append in unix shell scripting

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Truncate and Append in unix shell scripting
# 1  
Old 09-30-2009
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.

# 2  
Old 09-30-2009
You could use head command (has a byte count option...)
# 3  
Old 09-30-2009
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

# 4  
Old 09-30-2009
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX Shell Scripting

Describe in short the word completion feature of the tcsh Completion works anywhere in the command line, not at just the end, for both commands and filenames. Type part of a word and hit the Tab key, and the shell replaces the incomplete word with the complete one in the input buffer. The... (1 Reply)
Discussion started by: Elena Lauren
1 Replies

2. Programming

unix Shell scripting

Hi All, need help to complete the automation but stuck at a perticular situation below is the code <code> fixed_function_name { code.... code.... variable_map= { a="/a" b="/b" c="/c" so on... } (7 Replies)
Discussion started by: yadavricky
7 Replies

3. UNIX for Dummies Questions & Answers

Truncate date in UNIX

Hello everyone, I am trying to reproduce the following SQL statement in UNIX. Can anyone help me out with this one.. SELECT trunc(add_months(SYSDATE, -1), 'mm') FROM DUAL; date +"%Y%m%d" -d last-month This gives me last month date but I need to truncate that to 1st of that month. Any... (2 Replies)
Discussion started by: ronitreddy
2 Replies

4. Shell Programming and Scripting

UNIX Shell scripting

Hi, How to read .lst file line by line and while reading time it needs to copy the file into another file in unix shell script. could you please help in this issue. Thanks, Rami Reddy. (4 Replies)
Discussion started by: Rami Reddy
4 Replies

5. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

6. Shell Programming and Scripting

unix shell scripting

hi experts, i m a btech mini project is making a secure unix shell which is intented to stop mal practice in educational other words need to create a new shell in which commands like cp do not work....can anyone suggest me how to begin with it....refrence... (3 Replies)
Discussion started by: vikas MENON.S
3 Replies

7. Shell Programming and Scripting

Unix shell scripting

Hi All, I have one file called date1.txt and it contains dates like 130112 140112 150112 160112 170112 180112 190112 201012 so i need a script to read this file line by line and find out the day of each date and assign this value in one variable. And validate Weekday="Mon" then... (4 Replies)
Discussion started by: vichuelaa
4 Replies

8. Shell Programming and Scripting

How to search and append words in the same file using unix scripting file operations

Hi , I have a file myhost.txt which contains below, localhost atrpx958 atrpx958zone nsybhost I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone. How to search the word atrpx958(which is hostname) only,... (5 Replies)
Discussion started by: gsreeni
5 Replies

9. Shell Programming and Scripting

Shell scripting -append a new string

hi all , i am looking for a shell script which looks into a directory of text files and searches for a string(abc123) in all the text files and if that exists add a new line(abc124) in all the *.txt files automatically, or if (abc124) exists add (abc123) can you all please help me. (6 Replies)
Discussion started by: joseph.dmello
6 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question