Visit Our UNIX and Linux User Community


Help need in Deleting Characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help need in Deleting Characters
# 1  
Old 10-12-2009
Help need in Deleting Characters

Hi,

I have a log file whose size is number of characters in the file with multiple lines.

Example:
SQL*Loader: Release 10.2.0.4.0 - Production on Sat Sep 12 07:55:29 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Control File: ../adm/ctl/institution.ctl
Character Set WE8ISO8859P1 specified for all input.
Data File: /usr/home/dfusr/data/pe_proxy_master_2000_load_20090912075525.dat
Bad File: /usr/home/dfusr/data/bad/pe_proxy_master_2000_20090912075525.bad
Discard File: /usr/home/dfusr/data/bad/pe_proxy_master_2000_20090912075525.discard
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table PECDF.INSTITUTION_DF, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect


I want to delete some characters if the size of the file is greater that 32767. Delete all the characters after the 32767 i.e 32768 to last character in the file. The characters are in multiple lines.


Please advice or give me some sample code.

Thanks
Raj
# 2  
Old 10-12-2009
Something like this?

Code:
awk '{n=n+length+1}
n <= 32767
n > 32767 {n-=length;print substr($0,1,(32767-n));exit}
' file

# 3  
Old 10-12-2009
Hi,

What does it mean what is n and length in the sample.

Can you be specific please.

Thanks-
Rajesh
# 4  
Old 10-12-2009
Quote:
Originally Posted by rajeshorpu
Hi,

What does it mean what is n and length in the sample.

Can you be specific please.

Thanks-
Rajesh
n is a variable to store the number of bytes that has been read.

length is a builtin function to get the bytes (length) of the current line.

Beside the length you have to add 1 byte for the newline.
# 5  
Old 10-12-2009
Wrench

you could always use dd:

Code:
  dd if=infile bs=32767 count=1 > newfile


Previous Thread | Next Thread
Test Your Knowledge in Computers #347
Difficulty: Easy
AWK is a language for processing text files.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting Specific Characters in Script

What's one single UNIX pipeline that would delete all of the vowels from one file (global)? I know I would need to use the sed command. But I'm stuck after that. i know how to replace characters with other characters I just don't know how to fully get rid of it. (4 Replies)
Discussion started by: sarahahah
4 Replies

2. Shell Programming and Scripting

Deleting new line characters

Hi, I have a weird requirement. I am having a file with 12fields in it and the end of the line for each record is "\n" (Just \n and no carriage returns) and the field delimiter is "|". Problem is I can have new line characters in any field in the data and these new line characters can even come... (11 Replies)
Discussion started by: ngkumar
11 Replies

3. Shell Programming and Scripting

Deleting all characters before the last occurrence of /

Hi All, I have a text file with the following text in it: file:///About/accessibility.html file:///About/disclaimer.html file:///About/disclaimer.html#disclaimer file:///pubmed?term=%22Dacre%20I%22%5BAuthor%5D file:///pubmed?term=%22Madigan%20J%22%5BAuthor%5D... (8 Replies)
Discussion started by: shoaibjameel123
8 Replies

4. UNIX for Dummies Questions & Answers

Help with deleting characters from text file

I have a text file that looks like this: I want to delete the last character of first column in all rows so that my output looks like this: Thanks a lot! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

deleting rows that have certain characters

Hi, I want to delete rows whenever column one has the letters 'rpa'. The file is tab seperated. e.g. years 1 bears 1 cats 2 rpat 3 rpa99 4 rpa011 5 then removing 'rpa' containing rows based on the first column years 1 bears 1 cats 2 thanks (7 Replies)
Discussion started by: phil_heath
7 Replies

6. Shell Programming and Scripting

Deleting values with specific characters

I have a file with 3 columns 2 4 5 2 4 7 3 5 7 4 -6 9 5 -9 4 6 -3 3 Bascially I want to delete the entire row if column 2 is a "-" So the end result will be 2 4 5 2 4 7 3 5 7 I have trouble doing this cause of the - in front of the number. thanks (2 Replies)
Discussion started by: kylle345
2 Replies

7. UNIX for Dummies Questions & Answers

Need help with deleting certain characters on a line

I have a file that looks like this: It is a huge file and basically I want to delete everything at the > line except for the number after C. >c1154... (2 Replies)
Discussion started by: kylle345
2 Replies

8. Shell Programming and Scripting

deleting symbols and characters between two words

Hi Please tell me how could i delete symbols, whitespaces, characters, words everything between two words in a line. Let my file is aaa BB ccc ddd eee FF kkk xxx 123456 BB 44^& iop FF 999 xxx uuu rrr BB hhh nnn FF 000 I want to delete everything comes in between BB and FF( deletion... (3 Replies)
Discussion started by: rish_max
3 Replies

9. Shell Programming and Scripting

deleting last characters of a word

Hi All is there a way to delete last n characters from a word like say i have employee_new i want to delete _new. and just get only employee I want this in AIX Shell scripting Thanks (3 Replies)
Discussion started by: rajaryan4545
3 Replies

10. Shell Programming and Scripting

Deleting First Two Characters On Each Line

How would one go about deleting the first two characters on each line of a file on Unix? I thought about using awk, but cannot seem to find if it can explicitly do this. In this case there might or might not be a field separator. Meaning that the data might look like this. 01999999999... (5 Replies)
Discussion started by: scotbuff
5 Replies

Featured Tech Videos