vaas
March 25, 2011, 8:32am
1
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
ctsgnb
March 25, 2011, 8:45am
2
cut -c 1-75 abc.dat > tmp.dat
cat tmp.dat >abc.dat
rm tmp.dat
vaas:
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
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.
vaas
March 29, 2011, 2:09am
4
Thanks a lot...it was very useful for the beginner like me:)
thanks once again
ctsgnb
March 29, 2011, 3:51am
5
doxielvr:
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.
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.