tags: Bash

Read a File and Redirect the Output to the Same File

To write outputs to a file in a shell, we can use redirection. However, when we read a file and modify the content and redirect to the same original file, we'll get just an empty file. What's going on here? $ cat file bravo delta charlie alpha charlie $ cat file | sort | uniq > file $ cat file # empty file $ Of course, if you redirect to a different file and rename it to the original name, it works as expected.

Read more →

Gentaro "hibariya" Terada

Otaka-no-mori, Chiba, Japan
Email me

Likes Ruby, Internet, and Programming.