CUT command problem

Hi

I have a strange problem when using cut command

when i am using the below command, it is working fine,I am getting the data in new file xyz.dat

cut -c 1-75 abc.dat > xyz.dat

when i am using the below command, I am getting the data in new file abc.dat , but empty file

cut -c 1-75 abc.dat > abc.dat

could you help me out

Thanks in advance

cut -c 1-75 abc.dat > tmp.dat
cat tmp.dat >abc.dat
rm tmp.dat

The redirection ( > abc.dat ) is set up by the shell well before the cut program is executed. This replaces abc.dat with an empty file which cut then opens for input also.

You need to do something like

cut -c 1-75 abc.dat > abc.dat.tmp
mv -f abc.dat.tmp abc.dat

The nice thing about using mv instead of copy is that mv, if interrupted, guarantees to leave the original file intact.

Thanks a lot...it was very useful for the beginner like me:)

thanks once again

Yes but the inode of the target file will be lost.
using

cat abc.dat.tmp >abc.dat

and then

rm abc.dat.tmp

instead of

mv -f abc.dat.tmp abc.dat

will preserve it.

So all depends on what behaviour the user does expect.