3 ms·
Everyone has their own personal preferences. Here is how I would do that task, assuming (a) I had to do it more than once and (b) I could choose any software.
by 1vuio0pswjnm7 3y ago
Everyone has their own personal preferences.
Here is how I would do that task, assuming (a) I had to do it more than once and (b) I could choose any software. On the computer I'm using, the statically-linked, stripped binary is 50k versus a dynamically-linked gawk which is 623k. This solution is faster than AWK, Python, Go, etc. and uses much less CPU and memory. This is quick and dirty, written in a few minutes. I am not a paid programmer. I'm the so-called average user. I'm not compensated for writing programs.
usage: a.out <-- minimal typing
NB. There is a two space indent added to each line. One must remove exactly two spaces from each line or there will be error messages and this will not compile.
#!/bin/sh
flex -8Crf <<eof
int fileno (FILE*);
int x,y,n=1;
%option noyywrap noinput nounput
%%
^[A-Za-z][^\n]+ {
printf("%d ",n);
for(x=0;x<yyleng;x++){if(yytext[x]==32)y++;
if(y==1)putc(yytext[x],yyout);
}
putchar(10);y=0;
}
\n n++;
.
%%
int main(){ yylex();exit(0);}
eof
cc -O3 -std=c89 -W -Wall -pedantic -pipe lex.yy.c -static
- Brian_K_White 3y agoIf you suggested this as a joke, it is hilarious. Well done.