tags:

views:

106

answers:

4

i have some text files in a pre-defined directory, the files end with *.edi Each of them refers in one separate line within itself:

data_file   file_n.data

I have to convert this line in every .edi file to sth like

data_file   'another_directory/file_n.data'

i will add 'another_directory/ and ' in the end, because the data will be in another directory. and I have such 200 .edi files files, making it tedious to handle them manually! any help from regexp? I use UltraEdit engine for regexp by the way.

a_dir/
   file1.edi
   file2.edi
   file3.edi
   ...

and each file refers in one line:

data file   file_n.data

becomes:--->

data_file   'another_directory/file_n.data'
A: 

Replace the space(s) by space(s) followed by another_directory/ using appropriate metacharacters and escaping for /.

dirkgently
A: 

ultraedit has find and replace in files. If you're in v13+ it also has PERL compatible regexes.

If you turn on PERL compatible regular expression you can use:

For Find What: " (file_\d+.data)" (without the double quotes)

For replace with: " 'another_directory\/$1'" (without the double quotes)

For old style UltraEdit syntax regular expressions use:

Find What: " ^(file_[0-9]+^.data^)"

Replace With: " 'another_directory/^1'"

(without the quotes but the leading whitespace is significant)

Arnshea
+1  A: 

Just do a Replace in Files from the Search menu, using Perl Regular Expression Engine:

Find:

^(\s*data file\s+)(.+)$

Replace:

\1'another_directory/\2'

In Files/Types:

*.edi

Directory:

<whatever the directory with all your edi files is>

(tested in UltraEdit, works for me)

Chad Birch
Hi Chad, filenames are not file1.edi file2.edi but they appear on a separate line like "data file myfile.data.data" for 1st file and "data file another_file.data" for file2. so a bit more complicated...
yli
I'm not sure exactly what you mean, can you edit it into the question, showing exactly what the lines look like in the original file?
Chad Birch
data_file myfile.datadata_file another_file.datadata_file a_file.dataI mean each .edi file refers to its .data file with a different name.(the .data file name referred by I mean)it is not file1.data file2.data etc. as I wrote for the sake of writing the question easier to understand.
yli
That should be fine, my solution will handle that. All it does is look for a line that starts with "data file" (could have space in front), then has some space, then has something else (the file name). It changes the filename to have the directory in front and be surrounded by single quotes.
Chad Birch
THIS WORKS PERFECTLY!thx a lot.
yli
A: 

If I were using RegexBuddy's GREP tool, here's what I would do :

Match pattern:

^(data file\s{3})(file_n\.data)$

Options:

^$ match at line breaks.

Replace pattern:

\1'another_directory/\2'

I think UltraEdit should work pretty much the same.

Cerebrus