Click to See Complete Forum and Search --> : remove a string from a file in c


Jumux
04-26-2003, 03:14 PM
Whats a good way to remove a string from a file?

bwkaz
04-26-2003, 07:50 PM
sed -e 's/thestringtoremove//' <file >file.out

;)

Of course, you'll want to make sure that "thestringtoremove" only exists on one line; this will remove the first occurrence of it on every line it occurs in.

Jumux
04-28-2003, 05:10 PM
in c

mindcooler
04-28-2003, 05:19 PM
A common approach is to read the file you want to have lines/strings removed in and write the things you want to leave to a new file. When EOF is reached, you close both files, delete the original one and rename your new file to the name of the old one.

zdude255
04-28-2003, 07:30 PM
Originally posted by Jumux
in c


#include <stdlib.h>
system("sed -e 's/thestringtoremove//' <file >file.out ");


Its terrible style, but it works.