Gents,
I need to change 1 line of text in a large number of files, the line always starts with the same characters, but differs half way along. It is always in the sme position in the file (line 2). I need to sub the whole line for a different one.
Quick and easy, automated please? I want to dump all the files for changing in one directory, run whatever and job done?
write a little c console program to do it for you! :D
What format are the text doc's saved in? .doc or .txt or something else...
:coolio:
Any sort of text manipulation job would be best handled by a Perl script.
It's a bit of a bugger to learn though (as I'm finding out). Your best bet would be to try and find someone who knows Perl and get them to knock up a quick script for you.
its an xml file and I can't be arsed to learn PERL properly!
second line in about 50 .xml files need changing, c'mon gents, help me out.
used to know how to do basic file manipulation in C, written funny little programs that strip comments out of C files. So long as you know where in your file you want to make the changes and what the file format is like at the basic levels it's not too hard
I've never used Perl :withstupid: but I imagine it can't be too different to the C file.
Well, this is a different way to go about it. If you have DreamweaverMX create a new site. Put all the files in the site. Then select find and replace on the entire site and MX does the job :D. Not sure if it works with xml but worth a try.
Looks like you cannot do Search and Replace because although each line starts the same they change half way along.
Very complicated because it is always the second line you need to delete irrespective of what is in it.
A possible solution:
1. Copy file to new location
2. Strip out everything apart from first line - Call it copy 1
3. Make another copy and strip out first 2 lines - Call it copy 2
4. Append copy Number 2 to Copy number 1 - call it copy 3
5. Overwrite original with copy 3
Thats the logic sorted, can anybody provide some software?
one of you code heads must be able to do something like
VAR X
10 open file
20 where row x=[start of line] then delete row x
30 x=newtext
40 insert x
50 print Benny is Sexy
60 goto 50
I reckon sadako's suggestion of using an editor which can search and replace in multiple files at once would be easiest. tbh it'll probably take us as long to knock up a little program to do it as it'll take you to
open file,
select line,
paste new text,
save file,
close file.
50 times :nevermind:
oh, and if you did program it you could just search for the 2nd line in the text (but you would have to check the xml file formet to see any "hidden" text. Try opening up a .doc file in notepad if you dnot know whay I mean by that). You can jump to specific lines in data files quite easily, as there is a specific character that denotes end-of-line you can search for to decide where to paste your new text.
open OLD file
open NEW file
copy first line from OLD to NEW
copy NEWTEXT to NEW
copy rest of OLD to NEW
close all files
right, I better do some work
:rolleyes:
p.s. You might have fun getting it to automate the directory search, not done that before
I just noticed that you needed to put another line of text in sorry for missing that bit out.
Look, why don't you upload the files to an FTP server, tell us where they are, tell us what you want pasted in as line 2 and we'll do a file each. There are roughly 30 peeps in dMw plus forum regulars so it'll be done in no time.
PS it'll only cost a case of beer each :)
QuoteOriginally posted by BlueBall@Nov 19 2003, 03:40 PM
I just noticed that you needed to put another line of text in sorry for missing that bit out.
Look, why don't you upload the files to an FTP server, tell us where they are, tell us what you want pasted in as line 2 and we'll do a file each. There are roughly 30 peeps in dMw plus forum regulars so it'll be done in no time.
PS it'll only cost a case of beer each :)
apart from the obvious 'it's company data' :ph34r: and then the fact I've already done it all once <_< , I'm contracting here for the next week and a half. so I'm not overly fussed. :rolleyes: I t woulda been nice to leave a fully automated scanning system....
ooooo I'm a professional..... :dribble: :lmfao: .cue jokes.
professional what exactly? :narnar: :narnar:
I think of it as a positive learning experience :rolleyes: , or work avoidance...
right, I've got as far as making a console app that'll do it, but you have to specify the filenames from a command window and for some reason the last version is crashing at the end, although that's after it has converted all the files and like, finished. Debug goes through it clear...
anyhow, I dont know how to make it do drag and drop or directory searches, ...but if any of you fancy a go, here's the code...
#include <stdio.h>
#include <string.h>
#include <direct.h>
int main(int argc, char *argv[])
{
int n=0, done=0;
char nextfile[512];
char newnextfile[512]; //doesnt like undefined
char tempc=0;
char dirname[16]="updated";
FILE *in;
FILE *out;
if(argc==1)
{
printf("what? no files to convert?\n\ntype xmlstripper.exe filename1.xml filename2.xml\n\n");
return 0;
}
//makes a new directory called updated.
_mkdir(dirname);
printf("output files will be placed in %s\\\n\nProcessed files:\n----------------\n",dirname);
//scan directory for xml files or something?
for(n=1;n<=argc;n++) // repeat for all files somehow?
{
//if-else for testing.
//if(argc>1)
strcpy(nextfile,argv[n]); //gets input arguement
//else
// strcpy(nextfile,"Douglas.xml");
//open xml file
if(!(in=fopen(nextfile, "r")))
{
printf("halted: end of xml files or input arguement not a valid filename\n");
return 0;
}
else
{
//newnextfile = "BEN_OUT.xml";
strcpy(newnextfile, dirname);
strcat(newnextfile, "\\");
strcat(newnextfile, nextfile);
if(!(out=fopen(newnextfile, "w")))
{
printf("error opening %s\n",newnextfile);
return 0;
}
done++;
}
// copy up to to end-of-line
tempc=0;
while(tempc!=10){
tempc=getc(in);
putc(tempc,out);
}
// skip next line
tempc=0;
while(tempc!='\n'){
tempc=getc(in);
}
// insert new text for line2 <?xml-stylesheet href="languard2csv.xsl" type="text/xsl" ?>
fprintf(out,"<?xml-stylesheet href=\"languard2csv.xsl\" type=\"text/xsl\" ?>",10);
//copy rest of in to out
tempc=10;
while(tempc!=EOF){
putc(tempc,out);
tempc=getc(in);
}
fclose(in);
fclose(out);
printf("%s\n",nextfile);
}
//close any xml files that might somehow still be open
fcloseall();
printf("\ntotal %d xml files processed\n",done);
return 0;
}
will email a compiled version to you in a sec...
enjoy!!! :D
All hail the monkey. It works a treat, thanks Ben and to others who tried.
The deadmen community scores another victory for strange computer people helping eachother out. If I could I'd hug you all.
Thanks again.
strange computer people indeed :eyebrow:
B) rather glad I can still do some coding, might actually need it myself in the next few months...