I'm having trouble redirecting output to a file. Here's my example: I want to read in an existing file, replace all single newlines with two newlines, and save it. Here's what I've got:
Code:
cat -E documents/file.txt | sed 's/\$/\n/g' > documents/file.txt
|
However, when I open up file.txt, it's empty. What gives? Do I have to 'close' it, or something like that?
You don't have to open the file with cat.
Save it to file2.txt you could be overwriting it each time. You should never overwrite a file with itself.
Joomsy Wrote: [ -> ]You don't have to open the file with cat.
I tried using the '<' symbol (not sure what it's called), but I need a way to read every newline. The -E option displays a '$' before every newline. Is there a more efficient way to show non-printable characters?
trademark91 Wrote: [ -> ]Save it to file2.txt you could be overwriting it each time. You should never overwrite a file with itself.
So is it just an issue with output redirection? If so, I guess I could make the new file, delete the old, and rename the new one.
I think the > operator immediately truncates the file before cat can even open the file for reading.
I'd imagine that if cat would open the file for reading first, the line would actually work, due to how Linux handles reads and writes to a file at the same time.
Using the >> operator instead does work as expected, though this isn't what you want.
You're just doing a lot of erroneous spoon here.
There's no need for cat, and no need to output to the file.
said 'blah' file will do it just fine.