My file is like the following:
data_1.dat pre= -1908.77 post= -48977.33 diff= -448.947
data_2.dat pre= -444.333 post= -333.545 diff= -777.333
.
.
I hope to find out a regular expression subtitution commad to delete
everything after "dat" to get a file like:
data_1.dat
data_2.dat
.
.
I know visual mode will do the work too. But I still hope to find out
the substitution command using regular expression so I can use sed to
make it automatic.
Well, you're in luck...the Vim regexp can be the same regexp as
for sed:
s/\.dat[[:blank:]].*/.dat/
or possibly the slightly shorter
s/[[:blank:]]*pre=.*//
Some sed's may allow for vim's "\s" or "\>" notation, in which
case you can trim it even further:
s/\.dat\>.*/.dat/
or even
s/\s*pre=.*//
However, in your case, you might even be able to use the "cut"
program:
cut -d" " -f1 text
which just asks for the first field, when delimited by spaces (if
your original file uses tabs, you can ignore the -d" ", as cut
defaults to using tabs)
Just a few ideas...
-tim