Re: Deleting lines from big file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Re: Deleting lines from big file.
# 1  
Old 01-26-2011
Re: Deleting lines from big file.

Hi,

I have a big (2.7 GB) text file. Each lines has '|' saperator to saperate each columns.

I want to delete those lines which has text like '|0|0|0|0|0'

I tried:
Code:
sed '/|0|0|0|0|0/d' test.txt

Unfortunately, it scans the file but does nothing.

file content sample:
Code:
/2010|1|2842|C|9999999900099|0|083|484.09|879|4004.59|1363|6277.43|1118|5020.95
/2010|2|2842|C|9999999900099|0|1083|184.49|889|0|0|0|0|0
/2010|3|2842|C|9999999900099|0|103|428.99|899|4004.59|1363|6277.43|1118|5020.95
/2010|9|842|F|9999999900099|0|183|14.41|19|0|0|0|0|0

I want to delete 2rd and 4th lines (the original file has 47 million lines and there are many occurance of '|0|0|0|0|0').

Thanks in advance
Dip

Last edited by Franklin52; 02-26-2011 at 07:38 AM.. Reason: Please use code tags
# 2  
Old 01-26-2011
Quote:
Originally Posted by dipeshvshah
Hi,

I have a big (2.7 GB) text file. Each lines has '|' saperator to saperate each columns.

I want to delete those lines which has text like '|0|0|0|0|0'

I tried:
sed '/|0|0|0|0|0/d' test.txt

Unfortunately, it scans the file but does nothing.
Try grep -v "|0|0|0|0|0" <test.txt >output.txt It won't edit in-place, but then, sed won't either. And besides, I think you'd want to check your data to make sure you didn't destroy it before overwriting it, hm?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-26-2011
Thank you.
This User Gave Thanks to dipeshvshah For This Post:
# 4  
Old 01-26-2011
big file

1. Always check that you are using the correct tools. Sed is a stream editor, and is wonderful for making on-the-fly edits. What you want, though, is to select or deselect lines to retain. Finding and filtering lines this way is a 'grep' kinda thing. Used in the form 'fgrep' it finds strings, rather then regular expressions, and is a tool better suited to your purpose.
2. Perl is also capable, but may be overkill for what you want to do.
3. AWK could be made to do the same job, but would be awkward compared to grep. (pun intended: sorry)
# 5  
Old 02-25-2011
You have to redirect input to the command. Try following:

$ cat test.txt
Code:
/2010|1|2842|C|9999999900099|0|083|484.09|879|4004.59|1363|6277.43|1118|5020.95
/2010|2|2842|C|9999999900099|0|1083|184.49|889|0|0|0|0|0
/2010|3|2842|C|9999999900099|0|103|428.99|899|4004.59|1363|6277.43|1118|5020.95
/2010|9|842|F|9999999900099|0|183|14.41|19|0|0|0|0|0

Code:
$ sed -e '/|0|0|0|0|0/d' < test.txt
/2010|1|2842|C|9999999900099|0|083|484.09|879|4004.59|1363|6277.43|1118|5020.95
/2010|3|2842|C|9999999900099|0|103|428.99|899|4004.59|1363|6277.43|1118|5020.95


Last edited by Franklin52; 02-26-2011 at 07:39 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy only some lines from very big file?

Dear all, I have stuck with this problem for some days. I have a very big file, this file can not open by vi command. There are 200 loops in this file, in each loop will have one line like this: GWA quasiparticle energy with Z factor (eV) And I need 98 lines next after this line. Is... (6 Replies)
Discussion started by: phamnu
6 Replies

2. Shell Programming and Scripting

Want to extract certain lines from big file

Hi All, I am trying to get some lines from a file i did it with while-do-loop. since the files are huge it is taking much time. now i want to make it faster. The requirement is the file will be having 1 million lines. The format is like below. ##transaction, , , ,blah, blah... (38 Replies)
Discussion started by: mad man
38 Replies

3. UNIX for Advanced & Expert Users

Delete first 100 lines from a BIG File

Hi, I need a unix command to delete first n (say 100) lines from a log file. I need to delete some lines from the file without using any temporary file. I found sed -i is an useful command for this but its not supported in my environment( AIX 6.1 ). File size is approx 100MB. Thanks in... (18 Replies)
Discussion started by: unohu
18 Replies

4. Shell Programming and Scripting

Print #of lines after search string in a big file

I have a command which prints #lines after and before the search string in the huge file nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=0 a=10 s="STRING1" FILE The file is 5 gig big. It works great and prints 10 lines after the lines which contains search string in... (8 Replies)
Discussion started by: prash184u
8 Replies

5. Shell Programming and Scripting

deleting lines from file

We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Discussion started by: daveisme
8 Replies

6. UNIX for Advanced & Expert Users

Deleting lines from a file

How I can delete 100 lines anywhere in a file without opening a file and without renaming the file. (11 Replies)
Discussion started by: Nirgude07
11 Replies

7. UNIX for Dummies Questions & Answers

Deleting whole lines from a file

I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
Discussion started by: red baron
3 Replies

8. Shell Programming and Scripting

Deleting lines in a file

How do I delete all the lines after the line containing text ***DISCLOSURES*** . I want to delete this line too. Thank you (2 Replies)
Discussion started by: reachsamir
2 Replies

9. Shell Programming and Scripting

Deleting last 2 lines from the file.

Hi I have a file & always I need to remove or delete last 2 lines from that file. So in a file if I have 10 lines then it should return me first 8 lines. Can someone help me? (4 Replies)
Discussion started by: videsh77
4 Replies

10. Shell Programming and Scripting

Deleting Lines from .csv file

Hello All, I have a .csv file and I have to delete the selcted records stored in a vairable e.g echo $lname 7 88 91 94 97 100 103 106 I dont know how to pass the variable name to "sed" for deleting the $lname from a file can any one help as this is very urgent. $lname is changing the... (3 Replies)
Discussion started by: 009satya
3 Replies
Login or Register to Ask a Question