Deleting all characters from 350th character to 450th character from the log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting all characters from 350th character to 450th character from the log file
# 1  
Old 10-09-2009
Deleting all characters from 350th character to 450th character from the log file

Hi All,

I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position.



please advice or sample code.
# 2  
Old 10-09-2009
Is this is what you are looking for ?

Code:
sed 's/^\(.\{349\}\)\(.\{99\}\)\(.*\)/\1\3/' filename


Last edited by thegeek; 10-09-2009 at 02:54 PM..
# 3  
Old 10-09-2009
or use cut:

Code:
cut -c1-349,451- file

# 4  
Old 10-09-2009
Hi Thanks for your quick replay.

It is not deleting the charaters between nth character to nth character.

example:

123456789
abcdefghijklmnopqrst
xyzumnopqrst


i want to delete all character from k to n

please advice
# 5  
Old 10-09-2009
Are all the log file records the same length? How many characters in each logfile record?
# 6  
Old 10-09-2009
Following perl script will do the trick for you..
Code:
while(<>)  {
    $txt .= $_;
    $newline++;
    last if ( scalar split //, $txt ) >= ( 451 );
}

$txt =~ s/(.{350}).{100}/\1/s;

print $txt;
print while(<>);

Took a good amount of time to write & test...

Let me know the result.
# 7  
Old 10-12-2009
Hi Methly,

Thanks for your response,

The log file length varies.

some log files are 32765 B and some are 58853.
But what i want to do is..

If log file size exceeds 32767 B i want to delete some characters from the file and decrease the file size.

Example:

[pe_proxy_master.sh]: Oct 09 09:08:40 : *****Recieved DB Credentials*****
[pe_proxy_master.sh]: Oct 09 09:08:42 : Message : SUCCESSFULLY FETCHED TASK ATTRIBUTES FOR JOBID: 2060
[pe_proxy_master.sh]: Oct 09 09:08:42 : Starting [pkg_proxy_datafeed_api.USP_PROXY_DEL_DF_ROWS] using [JOBID:2060||JOBNAME:AGENDA||RUNNUMBER:1]...

Procedure Successfully Updated data for Run Status Id 588

PL/SQL procedure successfully completed.

[pe_proxy_master.sh]: Oct 09 09:08:44 : Control File Received [/usr/home/dfusr/adm/ctl/agenda.ctl]...Starting Program....
[pe_proxy_master.sh]: Oct 09 09:08:44 : Data File Received [/usr/home/dfusr/data/agenda.dat]...Starting Program....
[pe_proxy_master.sh]: Oct 09 09:08:45 : Loading [AGENDA] using SQL-Loader...

SQL*Loader: Release 10.2.0.4.0 - Production on Fri Oct 9 09:08:45 2009

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Commit point reached - logical record count 17
[pe_proxy_master.sh]: Oct 09 09:08:45 : >>>>> LOAD LOG [/tmp/pe_proxy_master.Fri.tmp] Content...<<<<<


SQL*Loader: Release 10.2.0.4.0 - Production on Fri Oct 9 09:08:45 2009

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Control File: /usr/home/dfusr/adm/ctl/agenda.ctl
Character Set WE8ISO8859P1 specified for all input.

Data File: /usr/home/dfusr/data/pe_proxy_master_2060_load_20091009090839.dat
Bad File: /usr/home/dfusr/data/bad/pe_proxy_master_2060_20091009090839.bad
Discard File: /usr/home/dfusr/data/bad/pe_proxy_master_2060_20091009090839.discard
(Allow all discards)

Number to load: ALL
Number to skip: 0
Errors allowed: 17
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional

Table "PECDF"."AGENDA_DF", loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect

Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
JOB_NBR FIRST * | CHARACTER
ALT_JOB_NBR NEXT * | CHARACTER
SECURITY NEXT * | CHARACTER
SQL string for column : "LTRIM(RTRIM(:security))"
RECORD_DATE NEXT * | DATE RRRRMMDD
AGENDA_NBR NEXT * | CHARACTER
COMMITTEE_TYPE_CD NEXT * | CHARACTER
COMMITTEE_NUMBER NEXT * | CHARACTER
PROPOSAL_CATEGORY NEXT * | CHARACTER
PROPOSAL_NBR NEXT * | CHARACTER
PROPOAL_LABEL NEXT * | CHARACTER
PROP_TYPE_CD NEXT * | CHARACTER
PROP_MRV NEXT * | CHARACTER
PROP_VOTE_OPTION NEXT * | CHARACTER
PROPOSAL_TXT NEXT * | CHARACTER
SQL string for column : "TRIM(Smilieroposal_txt)"
PROPOSAL_TXT_SEQ_NBR NEXT * | CHARACTER
APPOINTEES NEXT * | CHARACTER
SQL string for column : "LTRIM(RTRIM(:appointees))"
MAX_NBR_DIRECTOR NEXT * | CHARACTER
LANGUAGE_INDICATOR NEXT * | CHARACTER
JOB_TYPE NEXT * | CHARACTER

value used for ROWS parameter changed from 64 to 52

Table "PECDF"."AGENDA_DF":
17 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.


I want to delete from Number to load to null. in the last line.

Please advice.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

2. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

3. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

4. UNIX for Dummies Questions & Answers

Deleting all instances of a certain character from a text file

In my command prompt I did: sed 's/\://' mytextfile > newtextfile But it only deleted the first instance of : in each line when some lines have multiple : appearing in each one. How can I delete all the : from the entire file? (1 Reply)
Discussion started by: guitarscn
1 Replies

5. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

6. AIX

check for a particular character inside a file and substitute with a given character?

i am a newbie to shell script,so i want a kshell script in which i need to check for a particular character inside a file through conditional looping(like if ,case,while)and if that character exists ,then substitute a given character to that character. consider a file test.txt,inside the file... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

7. UNIX for Dummies Questions & Answers

read a variable character by character, substitute characters with something else

im having trouble doing this: i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's? im guessing its like getting the 1's compliment of the string im doing this in... (2 Replies)
Discussion started by: vipervenom25
2 Replies

8. UNIX for Advanced & Expert Users

Deleting end of line $ character in file

Hi, I've got a file where in the middle of the record is a $ end of line character, visible only when I open the file in vi and do :set list. How to I get rid of the character in the middle and keep it at the end. The middle $ character always appears after SW, so that can be used to tag it.... (3 Replies)
Discussion started by: bwrynz1
3 Replies

9. Shell Programming and Scripting

deleting newline characters but not the "true" \n character

hi, i have a file that has about 4500 rows. this was an old microsoft access databse and what i am trying to do is take out the old extra \n newline characters but not take out the "true" newline character. I will explain. i was trying to write a regular expression, but that was not... (1 Reply)
Discussion started by: caddyjoe77
1 Replies

10. UNIX for Dummies Questions & Answers

Problem deleting file with special character

I'm having problems deleting a file with a special character and I'm hoping that somebody here can help. The file "-osample1.c" will not remove from my directory. Here is an example of what happens. Any ideas would be appreciated. > ls *sample1* ls: illegal option -- . usage: ls... (2 Replies)
Discussion started by: hart1165
2 Replies
Login or Register to Ask a Question