Adding strings to text files..
#include <stdio.h>#include <malloc.h>#define ADD_WORD "WORD"int main(){ FILE *f1, *f2; char word[128], c; f1=fopen("infile","r"); f2=fopen("outfile","w"); while (!feof(f1)) { fscanf(f1,"%s",word); fprintf(f2,"%s%s",word,ADD_WORD); c=fgetc(f1); if (c == '\n') fprintf(f2,"\n"); else if (c == ' ') fprintf(f2," "); } fclose(f1); fclose(f2); return 0;}
Edited by - Maximus on November 2, 2001 11:59:02 PM
quote:Original post by Stoffel
Just kidding. You''ve got mad regexp skills.
Not really. For one thing, I got it wrong...
sed -e "s/[^ \n\t\v\f]+/\1$STRING/g" < in.txt > out.txt
And Arild, not it isn''t: http://unxutils.sourceforge.net/
For reasons that are unclear, ''+'' appears to be broken in that version of sed, so you''d have to use:
sed -e "s/[^ \n\t\v\f][^ \n\t\v\f]*/\0$STRING/g" < in.txt > out.txt
All your bases belong to us
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement