Reputation: 523
I googled this command but there was not.
grep -m 1 "\[{" xxx.txt > xxx.txt
However I typed this command, error didn't occured. Actually, there was not also result of this command.
Please anyone explain me this command's working?
Upvotes: 2
Views: 3112
Reputation: 58918
This command reads from and writes to the same file, but not in a left-to-right fashion. In fact > xxx.txt
runs first, emptying the file before the grep
command starts reading it. Therefore there is no output. You can fix this by storing the result in a temporary file and then renaming that file to the original name.
PS: Some commands, like sed
, have an output file option which works around this issue by not relying on shell redirects.
Upvotes: 1