Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

String manipulation & file I/O

Name: Anonymous 2007-05-13 1:42 ID:a16QPoC4

I have a text file full of thousands of md5 hashes from around the interwebs but they are seperated with newlines.

I need to open the txt hash file, and write to another file but replacing every newline with nothing.

Possible languages: Perl, C++ or Visual Basic 6.

Name: Anonymous 2007-05-13 2:19 ID:qNHJAn5T

YOu should just create a structure and save each line of your txt file in the structre and then write your structure in another txt file only if the containt of the structure isnt empty.

In vb.net it would be something like

for i=0 to stucture.length
if struc(i)<>"" then
FileName.WriteLine(struct(i))
end if
next

sorry I dont really the syntax in VB6

Name: Anonymous 2007-05-13 2:22 ID:/R3s1xXj

perl: perl -pl0e'#'

of course a real programmer would do it in c:
#include <stdio.h>

int main(){
 int len;
 char* line;
 while(!feof(stdin)){
  line=fgetln(stdin,&len);
  char l2[len+1];
  memcpy(l2,line,len);
  if(!feof(stdin))--len;
  l2[len]='\0';
  fputs(l2,stdout);
 }
 return 0;
}

Name: Anonymous 2007-05-13 2:24 ID:Heaven

actually, for perl you can just do perl -pl0e#

Name: Anonymous 2007-05-13 2:25 ID:qNHJAn5T

If I were you, I wouldn't consider myself a real programmer, cause 
C isn't even a fucking OBJECT PROGRAMMING.

.NET programming is the best

Name: Anonymous 2007-05-13 2:44 ID:bWPOo6FW

What the hell are you talking about? If C is good enough for Linux, the backbone of much of the interwebs, I would call it a good language.

NET programming is for M$ faggots.

Name: Anonymous 2007-05-13 2:51 ID:Heaven

>>5
CODE OR GTFO

Name: Anonymous 2007-05-13 3:15 ID:Heaven

>>4
That's exactly what >>3 said, except yours won't work because the # will be interpreted as a shell comment.

Name: Anonymous 2007-05-13 3:48 ID:f13Udn1X

HOW ABOUT U ALL STOP ARGUIN AND ANSWER THIS FAGGOTS QUESTION.

Name: Anonymous 2007-05-13 4:29 ID:PPi5+Ww2

tr -d '\r\n' < hashes.txt > output.txt

Name: Anonymous 2007-05-13 7:12 ID:Heaven

>>9
It's been answered like three times in this thread, what the fuck.

Name: Anonymous 2007-05-13 14:23 ID:BzsCe8FS

>>8
only if your shell is gay.

Name: Anonymous 2007-05-13 14:27 ID:HUnCdkSt

You fail programming if you can't do this.

Name: Anonymous 2007-05-13 14:30 ID:/yGofKKy

POST ANSWER OR GTFO FAGOTS OR I WILL BE PISSED OFF!!!

Name: Anonymous 2007-05-13 14:53 ID:Heaven

#!/usr/bin/env perl -pl0

Name: Anonymous 2007-05-13 15:21 ID:WzmyTv6c

Please write in a real language:
module Main (main) where

import Prelude hiding (writeFile, readFile, filter)
import Data.ByteString.Char8
import System.Environment

main :: IO ()
main = do
    arg <- getArgs
    case arg of
      [from,to] -> do
        content <- readFile from
                    `catch` (\_ -> fail $ "file does not exit: " ++ from)
        writeFile to (filter (== '\n') content)
         `catch` (\_ -> fail $ "could not write to file: " ++ to)
      _      ->
        fail "invalid arguments. use <fromfile> <tofile>"

This has the advantage of actually being fast:
[code]$ wc irc/Updike\,\ John\ -\ Rabbit\,\ Run\(v1.1\)\[htm\].html
 11617 102746 615253 irc/Updike, John - Rabbit, Run(v1.1)[htm].html

$ time ./whut irc/Updike\,\ John\ -\ Rabbit\,\ Run\(v1.1\)\[htm\].html blah

real    0m0.010s
user    0m0.004s
sys     0m0.004s
[code]

Name: dddddddddd 2007-05-13 15:26 ID:WzmyTv6c

erm, that should be, filter (/= '\n') content

:(

Name: Anonymous 2007-05-13 15:36 ID:Heaven

>>16
GAYFAG GTFO

Name: Anonymous 2007-05-13 16:01 ID:l3hRv5jA

NONE OF WHAT HAS BEEN POSTED IS ENTERPRISE ENOUGH

Name: Anonymous 2007-05-13 16:37 ID:FjXW1svk

perl, syntax ./program.pl inputfile


#!/usr/bin/env perl
use strict;
use warnings;

open my $out_h, ">", "/tmp/output.txt"
        or die $!;

while (<>) {
        s/\n//g; # replace newline
        print {$out_h} $_;
}

Name: Anonymous 2007-05-13 16:53 ID:Heaven

>>20
horrible.

Name: Anonymous 2007-05-13 16:56 ID:nJ3/ypUI

>>21
No, it's Perl.

Name: Anonymous 2007-05-13 16:57 ID:8NlcJ88O

Its a sed one liner, and its one of the first things in any sed tutorial. Stop overcomplicating this /prog/ (hah)

Name: Anonymous 2007-05-13 17:00 ID:K8Wp/bcz

>>23
Never try to keep /prog/ from overcomplicating. You will only make it angrier.

Name: Anonymous 2007-05-13 17:15 ID:OKC/aQcW

>>22
What >>21 said

Name: Anonymous 2007-05-13 17:35 ID:Heaven

Name: Anonymous 2007-05-13 18:16 ID:u+nIURND

In before someone writes it in Brainfuck.

Name: Anonymous 2007-05-13 18:23 ID:jyre8V2L

>>23
There's too many VB and Java "professionals" here to keep stuff simple and elegant, live with it.

I'm not saying you couldn't be a decent programmer and work with Java, it's just that most people who prefer it over other languages aren't that skilled in others.

Name: Anonymous 2007-05-13 18:28 ID:Heaven

>>28
Javafags yes, but are there really any active VB programmers here? I don't remember seeing any actual VB code in here for ages.

Name: Anonymous 2007-05-13 18:31 ID:Heaven

>>21
>>22
>>25
What? It's beautiful, reads like a poem.

Name: Anonymous 2007-05-13 18:36 ID:Heaven

>>30
The amount of magic symbols used in idiosyncratic perl code makes it completely unreadable to anyone except other perl programmers.

Name: Anonymous 2007-05-13 22:43 ID:UHeJtlXS

The proper way to deal with the OP is to question his motives.

Why would you want to remove newlines from the file? Either store the hashes in a text file with some sort of separator, or store them as pure binary. Not some kind of shit semi-text format.

Name: Anonymous 2007-05-13 23:26 ID:Qg00uqNK

>>32
good call. No clue why anyone would store without a notifiable seperator.

Name: Anonymous 2007-05-13 23:41 ID:Heaven

>>33
Going for world record? "Largest concatenated md5 hash".
Mad scientist experiment? "Yes... I hold all the world's md5 hashes hostage, and if I do not get ONE MILIEEN DOLLARS within 24 hours, I will squeeeeze them together until the information density creates a deegital black hole, sucking the tubes of the eenternet dry!"
Post it on messageboards to make a really long unbroken line and fucking up the page layout?

Name: Anonymous 2007-05-13 23:42 ID:nJ3/ypUI

Because md5 hashes have a static length, regardless of whether they're stored in binary form or as a hex string. OP is probably too retarded to know that the hexadecimal can also be `converted' into binary.

Name: Anonymous 2007-05-14 4:36 ID:Heaven

every program here is overkill anyway
do{s/\n//g and print}while <>

Name: Anonymous 2007-05-14 7:01 ID:vP4SqUBa

file('out', 'w').write(file('a').read().replace('\n', ''))

Name: Anonymous 2007-05-14 7:17 ID:ZHIIo/8k

>>36
Overkill? In MY /prog/?

Name: Anonymous 2007-05-14 8:47 ID:Heaven

>>36
your program is overkill.
see >>4 and >>15.

also, tr -d \\n

Name: Anonymous 2009-07-28 23:32

                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |
                                        |

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List