Originally Posted by accesskarthi
awk '$2!='$date testfile > testfile
but the testfile is empty.
when i tried to write the output to another file it worked.
awk '$2!='$date testfile > newtestfile
Kindly guide me to resolve this.
The ">" operator for redirection is not a facility of awk, but the shell.
Never try such things!!! The source file will be truncated.
The main cause is that the shell is not so smart to understand all of your needs.
For example, if you say $> cat file > file
then the shell in order to dump the output of 'cat' command to file 'file', it first tries to open the file.
If that file 'file' exist (obviously in this case), it opens it with O_TRUNCATE flag, i.e. it content will be truncated and the 'cat' decently cat's the empty file.
So always redirect the output to temp file and then move it to original.