How to Delete string without opening a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Delete string without opening a file
# 1  
Old 11-01-2008
How to Delete string without opening a file

Hi Experts,

I have several big size file arround 900 MB. From the file I need to delete some common strings but without opening the file. here is example- in file

<?xml version='1.0' encoding='ISO-8859-1' standalone='no'?>
<LogItems>
<log logid="8423b5ae190810252359350480/1/1/1">

<category>ProcEngineBL.Normal</category>
<operation>DC::sendGetCommand</operation>
<starttime>20081025235935.515410</starttime>
<stoptime>20081025235935.723993</stoptime>
<status>FAILED</status>
</log>
<log logid="8423b5ae190810252359350480/1/1">
<category>ProcEngineBL.Normal</category>
<operation>Get</operation>
<target>DC.Subscription</target>
<fullOperation>DC::getCommand</fullOperation>
<starttime>20081025235935.508385</starttime>
<stoptime>20081025235935.724373</stoptime>
<status>FAILED</status>
</log>
<log logid="8423b5ae136366384884759350480/1/1">
<category>ProcEngineBL.Normal</category>
<operation>Get</operation>
<target>DC.Subscription</target>
<fullOperation>DC::getCommand</fullOperation>
<starttime>20081025235935.508385</starttime>
<stoptime>20081025235935.724373</stoptime>
<status>FAILED</status>

I want to delete the above Red Colored Strings from the File but without opeining the file. You know its 900MB file. so, its time consuming to open.

Please help.
# 2  
Old 11-01-2008
If you want to modify a file you always have to open something (either using kernel's filesystem implementation or doing it the forensic way by opening a device directly and using the filesystem libs on user-space to control exactly what you're doing).

Anyway, the problem is not opening a file but reading it! And yet, I always have to read the file and then handle strings/patterns to delete something.

Hence,
Code:
 sed "/<\/log>/ { N; s/<\/log>\n<log logid=\"8423b5ae136366384884759350480\/1\/1\">//; s/<\/log>\n<log logid=\"8423b5ae190810252359350480\/1\/1\">// }" YOUR-900MB-FILENAME-HERE > new900MBfileWithoutThoseTwoEntries

This might take a while.
# 3  
Old 11-01-2008
Cant we do something like this?
sed -n -e '/<log logid="8423b5ae190810252359350480/1/1">/d' file.txt > file.txt
# 4  
Old 11-01-2008
Quote:
Originally Posted by incredible
Cant we do something like this?
sed -n -e '/<log logid="8423b5ae190810252359350480/1/1">/d' file.txt > file.txt
no, you can't. You'd overwrite you input source while reading it.
# 5  
Old 11-01-2008
Quote:
Originally Posted by reborg
no, you can't. You'd overwrite you input source while reading it.
Yeah, and furthermore this is a multi-line match.
# 6  
Old 11-01-2008
man sed
Code:
.....
       -i[SUFFIX], --in-place[=SUFFIX]

              edit files in place (makes backup if extension supplied)

# 7  
Old 11-03-2008
Code:
sed '/<\/log>/{
N
s/<\/log>\n.*\/1\/1">//
}' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

2. UNIX for Dummies Questions & Answers

How to read a file without opening the file and delete last line?

I have file called "text". The contents are as below : aaa bbb ccc ddd eee ffff ddd hhhh iiii I want to read this file without opening and and delete the last line. How can it be done? (4 Replies)
Discussion started by: the_hunter
4 Replies

3. Shell Programming and Scripting

Compare two string in two separate file and delete some line of file

Hi all i want to write program with shell script that able compare two file content and if one of lines of file have # at the first of string or nothing find same string in one of two file . remove the line in second file that have not the string in first file. for example: file... (2 Replies)
Discussion started by: saleh67
2 Replies

4. UNIX for Dummies Questions & Answers

search for a string and delete it from the file

Hi , I am breaking my head from past one day ...to delete lines from a file which match to the string pattern.:wall: I am storing the search string in a variable and search if the file exists in the folder,if not delete that entry from the file. I am having problem to delete that line from... (2 Replies)
Discussion started by: rashmisb
2 Replies

5. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

6. Shell Programming and Scripting

How to delete selected string from a file?

awk '!(/^$/||/--/||/selected/||/^ *$/){print "A." $1 " <> B." $1 " or"}' infile my AWK out put is : A.KZ <> B.KZ or A.KZT <> B.KZT or A.KZ_Z <> B.KZ_Z or A.LH <> B.LH or A.MAN<> B.MAN or A.OBJEKT <> B.OBJECT or A.PAK <> B.PAK ; is there any way to controle AWK to not print the... (1 Reply)
Discussion started by: kanakaraju
1 Replies

7. Shell Programming and Scripting

How to delete a string pattern in a file and write back to the same file

I have a control file which looks like this LOAD DATA INFILE '/array/data/data_Finished_T5_col_change/home/oracle/emp.dat' PRESERVE BLANKS INTO TABLE SCOTT.EMP FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS (................. ..................) How can i edit the... (1 Reply)
Discussion started by: mwrg
1 Replies

8. UNIX for Dummies Questions & Answers

Urgent help needed to delete some text without opening the file in unix

Hi To delete some text in 2 files in line1 ( not complete line) in unix without opening the files. For example: source file is like this <?xml version="1.0"... (5 Replies)
Discussion started by: pyaranoid
5 Replies

9. Shell Programming and Scripting

How to delete a particular text without opening the file.

Hi, Could someone tell me how to delete a particular text inside an existing file without opening the file? e.g. I have a text file called mytext.txt which contains three lines of text below and I want to delete “ ;” and delete the second line “b ;” including the carriage return. a ; b ; c ;... (12 Replies)
Discussion started by: stevefox
12 Replies

10. UNIX for Dummies Questions & Answers

delete file without opening vi

hi there guys, wonder if any gurus can help me out on this one... try searching the past threads but cant find anything. i have this huge file but when i use vi to open it it gives me the following error: <"pmrepserver.txt""/var/tmp/Ex86200" There is not enough space in the file... (7 Replies)
Discussion started by: lweegp
7 Replies
Login or Register to Ask a Question