Fast append before string on each new line -
i have couple of pretty large text-files (1 gb each) have 1 generated word on each line. want append string before each of generated words. whether it's java, c#, c, c++, or ruby doesn't matter. while can't program myself, can compile , run it.
example:
file.txt:
aoos ahsd gaata sdffg
output:
appendaoos appendahsd appendgaata appendsdffg
any welcome!
depending on tools have available, can use sed
, awk
or perl
:
sed 's/^/append/' inputfile >outputfile awk '{print "append"$0}' inputfile >outputfile perl -pne 's/^/append/' inputfile >outputfile
if want write own program, can filter programs relatively easy in c:
#include <stdio.h> int main (void) { int ch, lastch = '\n'; while ((ch = getchar()) != eof) { if (lastch == '\n') printf ("append"); putchar (ch); lastch = ch; } return 0; }
just compile as, example, myprog
, run:
myprog <inputfile >outputfile
Comments
Post a Comment