Basic text file edit

K

keithkeith

How can I build a macro to run on the command-line to do a simple editing of
a text file with a regular pattern to it?
I want to change the text file contents of:
200705230822
200705231341
200705230904
to end up as:
052320070822
052320071341
052320070904
 
G

Graham Mayor

The macro is largely superfluous here
With the patterns shown a simple wildcard search for
(2007)(0523)([0-9]{4})
replace with
\2\1\3
will do the job

If the first part are changeable dates you could use a search string of
([0-9]{4})([0-9]{4})([0-9]{4}) instead (replace string is the same) but I
would prefer to tie the year down more tightly - see
http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

keithkeith

Thank you, but my data sample was too simplistic. Please consider this
scenario:
I want to change only the two last date fields formatted as yyyymmddhhmm to
mmddyyyy in a text file such as:
2133 AB 200705240233 200705240929
0119 RG 200610011921 200711122300
to:
2133 AB 05242007 05242007
0119 RG 10012006 11122007
where all fields are fixed length, and all field positions are known. Is it
possible to get this macro to run automatically from a command line call?
Thank you for any hints.

Graham Mayor said:
The macro is largely superfluous here
With the patterns shown a simple wildcard search for
(2007)(0523)([0-9]{4})
replace with
\2\1\3
will do the job

If the first part are changeable dates you could use a search string of
([0-9]{4})([0-9]{4})([0-9]{4}) instead (replace string is the same) but I
would prefer to tie the year down more tightly - see
http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

How can I build a macro to run on the command-line to do a simple
editing of a text file with a regular pattern to it?
I want to change the text file contents of:
200705230822
200705231341
200705230904
to end up as:
052320070822
052320071341
052320070904
 
D

Doug Robbins - Word MVP

You can do it with a wild card search that uses

(<[0-9]{4})([0-9]{4})([0-9]{4}>)

in the Find what control and

\2\1

in the Replace with control

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

keithkeith said:
Thank you, but my data sample was too simplistic. Please consider this
scenario:
I want to change only the two last date fields formatted as yyyymmddhhmm
to
mmddyyyy in a text file such as:
2133 AB 200705240233 200705240929
0119 RG 200610011921 200711122300
to:
2133 AB 05242007 05242007
0119 RG 10012006 11122007
where all fields are fixed length, and all field positions are known. Is
it
possible to get this macro to run automatically from a command line call?
Thank you for any hints.

Graham Mayor said:
The macro is largely superfluous here
With the patterns shown a simple wildcard search for
(2007)(0523)([0-9]{4})
replace with
\2\1\3
will do the job

If the first part are changeable dates you could use a search string of
([0-9]{4})([0-9]{4})([0-9]{4}) instead (replace string is the same) but I
would prefer to tie the year down more tightly - see
http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

How can I build a macro to run on the command-line to do a simple
editing of a text file with a regular pattern to it?
I want to change the text file contents of:
200705230822
200705231341
200705230904
to end up as:
052320070822
052320071341
052320070904
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top