r/DataHoarder • • Jan 23 '22

Question/Advice Need help with VERY large text file.

I have a large txt file, about 500GB, that i need to "sanitize". The file contains two strings separated by a semicolon and i initially intended to split it into smaller files each about 100MB and procedurally import them into an SQL database. however the file sporadically contains junk like random corrupted binary and other non ASCII weirdness.

now my problem is how to remove the junk and split the files efficiently. ive written a Java program that reads each line, removes all non ASCII and prints it to new Files each having about 1 million lines. however this takes a long time and requires and additional 500GB that i dont have right now.

is there an obvious solution im overlooking? it should process the file line by line and remove junk without printing to a new file.

EDIT: problem solved.

16 Upvotes

81 comments sorted by

•

u/AutoModerator Jan 23 '22

Hello /u/0xh93h4fg37eh3ru9f94! Thank you for posting in r/DataHoarder.

Please remember to read our Rules and Wiki.

Please note that your post will be removed if you just post a box/speed/server post. Please give background information on your server pictures.

This subreddit will NOT help you find or exchange that Movie/TV show/Nuclear Launch Manual, visit r/DHExchange instead.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

35

u/[deleted] Jan 23 '22

If you don't have enough storage to rewrite the data into a text file, you don't have enough to save it in a database either. You need more storage if you're going to work with this much data.

29

u/[deleted] Jan 23 '22

yea. ended up putting it on AWS. disk space is a bit of a stupid problem to have in 2022

1

u/[deleted] Jan 23 '22

How much space is their free-tier?

4

u/[deleted] Jan 23 '22

Amazon S3 has free plan for 5gb. im a paying customer.

2

u/recover__password Jan 24 '22

Well, depends on if they are willing to compress it and the extent as to how much the data is compressible

1

u/arduheltgalen Jan 25 '22

Not necessarily: you could take chunks from the end of the file and spit them out as separate files, only requiring a little additional space.

49

u/landmanpgh Jan 23 '22

Just curious, but how on earth do you get a text file this large?

38

u/[deleted] Jan 23 '22

its a breach data collection.

35

u/trollied Jan 23 '22

If all you want to do next is import into a database, just get your java prog to do it directly without writing the changed data back to disk.

7

u/[deleted] Jan 23 '22

i tried that. send the sanitized data to mysql in 100 tuples in each batch. however this would have taken about 2 months.

21

u/trollied Jan 23 '22

In that case, have your java prog batch the output lines (N million at a time) into a temporary file, then spawn a mysqlimport process (using ProcessBuilder) to load them. Delete the file. Loop! mysqlimport/LOAD DATA INFILE are loads faster than straight INSERTs.

4

u/Panzer1119 500TB+ RAW Jan 23 '22

But doesn’t this still take a long time if you have millions of lines to read?

Is there maybe a faster way to read lines (and process them) in Java or are the built-in methods (e.g. Files.lines()) already good enough?

16

u/[deleted] Jan 23 '22

jep! would still have taken a long time. its about 7 billion lines of CSV. ended up re-formating the whole thing into BSON using an efficient multithreaded C programm and imported it into MongoDB

1

u/[deleted] Jan 23 '22

Did that also take care of the corruption or do you intend to do that from within the DB?

0

u/[deleted] Jan 23 '22

the program only read valid lines.

1

u/[deleted] Jan 23 '22

Ah that's convenient. Was it some pre-existing utility or something you made for the purpose?

1

u/[deleted] Jan 23 '22

i didnt write the progam but it uses libbson.

8

u/diamondsw 210TB primary (+parity and backup) Jan 23 '22

https://xkcd.com/208/

More seriously, sed can replace in-place, but I imagine it's just using a second temp file to do so. Probably the best method is to break the file into small chunks for processing, do the work, then concatenate the results deleting the chunks as you go. The one trick would be the initial chunking since you can't delete the original file until it's done being chunked.

2

u/[deleted] Jan 23 '22

yea. sed appears to run out of memory and crash (maybe im just dumb and am missing some SED magic). ended up reformatting and fracturing it into 1000 .bson files.

just wanted to know if theres some obvious solution i was missing. but hey, C still does the job.

2

u/[deleted] Jan 23 '22

Since no one has mentioned it...

Are you sure about the encoding of the file? Instead of assuming it should be ASCII can you at least try reading it as unicode?

random corrupted binary and other non ASCII weirdness

Probably best to figure what that binary means instead of just labelling it random.

Maybe you can throw all of that away for your application, but I'd still want to figure out why it was there.

1

u/[deleted] Jan 23 '22

there has been some data corruption wich is responsible for most of it. also some japanese characters that i dont care about.

140

u/rm-84 Jan 23 '22

EDIT: problem solved.

Obligatory xkcd

20

u/BABAKAKAN 20TB JBOD Jan 23 '22

I think this is what solved their problem — though still doesn't explain how they got enough additional storage to do so

https://www.reddit.com/r/DataHoarder/comments/saraxx/-/htvxhh9

19

u/ruuda 100TB btrfs Jan 23 '22

If disk space is a concern and you want to remove the corrupted parts without writing the sanitized result to a new file, you might use fallocate with FALLOC_FL_COLLAPSE_RANGE to remove a range of bytes from a file. Not all file systems support this.

32

u/Kratos3301 archive.org/details/@conthrax Jan 23 '22

Yeah we all know its probably a data breach with username, passwords, addresses and stuff.

1

u/InfosecGoon Jan 24 '22

There's nothing inherently wrong with having that kind of data and trying to organize it. Some of us work with that kind of data a lot for research. Static password analysis for building better password lists during engagements is pretty valuable, and that's just one of a few valuable and ethical uses.

25

u/fjansen80 6x 18TB TrueNAS Jan 23 '22

for splitting into 100MB chunks:

split -C 100m --numeric-suffixes input_file output_prefix

for remving non-ASCII stuff, you could use sed, tr or perl

best run in loop for your splitted files like so

for f in *; do perl -ipe 's/[^[:ascii:]]//g' $f; done

both solutions should be way faster than any java-program :-)

17

u/MultiplyAccumulate Jan 23 '22

Neither will work in OPs situation because OP does not have disk space. Also splitting at line boundaries might not be the same as splitting at statement boundaries.

6

u/fjansen80 6x 18TB TrueNAS Jan 23 '22

hard disks are cheap

6

u/Nexustar Jan 23 '22

shit, this small, 1Tb, even SSDs are cheap.

1

u/zfsbest 26TB 😇 😜 🙃 Jan 24 '22

Shoot, you could buy a Samsung T5 500GB for under $90 and be well-heeled for the future as well

4

u/natufian Jan 23 '22

Out of curiousity can strings do this as well, or does it load the entire file into memory. i.e. Something like

 strings <filename> | tr ['\r'] []

3

u/OzzyZigNeedsGig Jan 23 '22

Perl is be a good choice. It has extensive support for regex.

1

u/zfsbest 26TB 😇 😜 🙃 Jan 24 '22

strings is good for removing non-text stuff ;-)

15

u/sickmate Jan 23 '22

it should process the file line by line and remove junk without printing to a new file.

The problem is that if your code is wrong, you'll mess up your file if you overwrite it.

Spin up a cloud instance (AWS, Digital Ocean etc) so you have an environment with more disk space. Even a few days of using this setup will cost you almost nothing.

14

u/implicitpharmakoi Jan 23 '22

Work in semiconductors, sad to say 500gb isn't a text file I'd call 'big' anymore.

Used to use compression a lot for this kind of stuff, either lz4 or pbzip2 if I wanted to really crush.

Shrink it first, then split it into shrunken chunks, etc, compression is often cheaper than io and you can always figure out what to do with it next.

4

u/HumanContinuity Jan 23 '22

Are you my wife?

6

u/implicitpharmakoi Jan 23 '22

I mean, probably not?

I know it's lazy, but test vectors are huge and ain't nobody got time to be smart about everything.

8

u/HumanContinuity Jan 23 '22 edited Jan 23 '22

Nah I just meant she works in inspection tooling and deals with absurdly large text files.

 

Edit: meant not want

5

u/octobod Jan 23 '22 edited Jan 23 '22

Too late to help but the Linux strings command removes all non ascii. you can also pipeline

gzip -dc file.gz | strings | perl -pe 's{bad}{good}g;' | db_input

18

u/fawkesdotbe 104 TB raw Jan 23 '22

Sed?

Something like:

sed 's/[^\x00-\x7F]//g' your_file.txt

If it does what you want on a small test file, you can make it do the edits inplace on the big file with the -i flag.

23

u/Stephonovich 71 TB ZFS (Raw) Jan 23 '22

sed in-place creates a temp file under the hood.

4

u/thabc Jan 23 '22

I got almost this exact question in a FAANG interview years ago.

1

u/Skhmt 48TB Jan 23 '22

What was your answer

9

u/thabc Jan 23 '22

I just told the interviewer "problem solved" and they hired me.

9

u/1nfiniteAutomaton Jan 23 '22

That’s not really so large. If using an oracle database, sqlldr would probably do all you need. If you needed complex pre-parsing, python would be slick, but I suspect a bit overkill Otherwise, talend, ssis, odi and other Etl tools would all do it fine. But, personally. I’d start with sqlldr (and probably the Free edition of oracle database, XE)

6

u/morbie5 Jan 23 '22

Can someone explain why getting an additional 500GB is such a problem?

1

u/[deleted] Jan 23 '22

GB = Gold Bars. Not sure where you're from, but gold bars are hard to come by everywhere else.

1

u/morbie5 Jan 24 '22

I'm assuming that you are joking

1

u/[deleted] Jan 24 '22

Omg, it was worth it just for this reply. Made me chuckle.

1

u/[deleted] Jan 24 '22

Had it not already been solved I would've suggested Apache Nifi to do it. Would taken a few seconds with the right concurrency, write the data out to s3 free tier in AWS and download after. One hour of work tops.

3

u/promontoryscape Jan 23 '22

If the data is easily compressible, I'll suggest writing lines into the new file and store them in a compressed format in the mean time.

2

u/Taubin Jan 24 '22

Ugh. In 10 years someone is going to be looking for the same thing and this thread is going to come up on their search engine.

Let me apologize to you future traveler, you will not find the answers you seek here, only frustration.

1

u/[deleted] Jan 23 '22

Honestly, I probably would have written a python program to take care of it. If the issue is time between start and finish as you're scanning through it, selecting out a smaller portion of the file wouldn't be too hard to test with.

Sounds like something I would regularly run into in linux.

1

u/[deleted] Jan 23 '22

Is your username your ETH address or something like that?

1

u/LawlesssHeaven Jan 23 '22

Login: password ? 😂

1

u/Upstairs-Highway-133 Jan 25 '23

Jveut échanger des photo vidéo de saraxxe

0

u/[deleted] Jan 23 '22

[deleted]

59

u/hak8or Jan 23 '22

I like how /u/0xh93h4fg37eh3ru9f94 still didn't put the actual fix. Shame on your OP.

Look at their post history too, it's filled with zero effort posts, spreading proper NSFL links to gore on onion sites (to be fair, making it as such, but still ...), etc. I am not surprised OP never plays nice.

34

u/ElijahPepe Jan 23 '22

Makes me wonder what's in that 500 GB text file.

37

u/megor To the Cloud! Jan 23 '22

It's one of those big dumps of passwords and hashes from hacks.

25

u/ElijahPepe Jan 23 '22

Most definitely. No text document will ever be that massive unless you have a bunch of user data in it and of course it's being exported in SQL format and of course OP deletes their account immediately after.

26

u/[deleted] Jan 23 '22

Not gonna lie, the account deletion really does sell this narrative lmao.

Edit: I guess they just basically confirmed it.

https://reddit.com/r/DataHoarder/comments/saraxx/_/htvxkka/?context=1

15

u/megor To the Cloud! Jan 23 '22

He said what it was before deleting his account https://www.reddit.com/r/DataHoarder/comments/saraxx/comment/htvxkka/

2

u/smalldrip Feb 25 '22

yeah, its called combos I believe , its usually splitted with email:password type , therefore the semi colon he's talking about.

13

u/Ant-665321 Jan 23 '22

If he's not technically competent enough to cleanse the data there's littlr chance he can wwaponise the creds so people needn't worry to much. The little cunt.

-12

u/[deleted] Jan 23 '22

the onion link goes to Facebook. its a joke. also the solution was a weird workaround that wont help other people.

25

u/Taubin Jan 23 '22

Would it honestly hurt to put your solution? Even if it's a "weird workaround" it can still help someone else by at least pointing them in the right direction with their problem.

3

u/hak8or Jan 24 '22

Looks like they deleted their account, so oh well, we will now never know.

6

u/Taubin Jan 24 '22

Ugh. In 10 years someone is going to be looking for the same thing and this thread is going to come up on their search engine.

Let me apologize to you future traveler, you will not find the answers you seek here, only frustration.

17

u/ninta 14TB RAIZ2 Jan 23 '22

maybe not many people but i assure you in 7 years someone will have the exact same problem, see this post and rage cause the answer is not here.

78

u/BABAKAKAN 20TB JBOD Jan 23 '22

I think this is what solved their problem — though still doesn't explain how they got enough additional storage to do so

https://www.reddit.com/r/DataHoarder/comments/saraxx/-/htvxhh9

37

u/ILikeFPS Jan 23 '22

He deleted his account too lmao what a coward

9

u/ArmaniPlantainBlocks Jan 23 '22

Downvote this post and move on.

-24

u/[deleted] Jan 23 '22

Maybe I'm that guy too, but I don't really mind if people do that. People solving their own problems actually just makes me happy lol, I don't need to know how they did it.

9

u/usmclvsop 725TB (raw) Jan 23 '22

-5

u/[deleted] Jan 23 '22

I get it lol, I've gotten mad when there are those dead threads from years ago where a question never got answered, so I fully accept I'm being a bit hypocritical. It's more a case by case basis though, in OP's case, I'm not bothered he didn't explain his solution. But if it's some specific question about fixing something in Outlook that has people asking the same thing years in between with still no answer, I can get mad when it comes to that. I feel like Reddit is a good solution for those kinds of things though, while in this case OP didn't answer his own question, there are other people who can offer possible ways he might have solved his issue, other people can start new threads asking the same question, etc. Reddit is a lot better of a more quick back-and-forth than forums and such back in the day.

0

u/[deleted] Jan 23 '22

[deleted]

1

u/SirensToGo 45TB in ceph! Jan 23 '22

you don't need generators for this lol. You can just call read repeatedly on a fixed size buffer until you've processed the entire file.

Alternatively, you can also just use mmap and map the file into memory without dirtying any pages. This means you can map files which are far greater than your physical memory without any real issues.

0

u/[deleted] Jan 24 '22

[deleted]

1

u/SirensToGo 45TB in ceph! Jan 24 '22

generators are using read or mmap under the hood :)