简体   繁体   中英

Bash shell: Appending a newline after each input in a *.txt file

I am trying to save a list of numbers from 1 to 10 in a text file in bash, each on it's own line.

This is the code I used:

echo "1" >> test.txt
echo >> test.txt
echo "2" >> test.txt

When I call my file with cat test.txt , it prints out the numbers exactly like it needs to:

=> OUTPUT:

1

2 

etc...

But when I open the .txt file outside of bash, the information is saved as: 12345678910

This does what you want

for i in `seq 1 10`; do echo $i >> test.txt; done

But trust cat over "Windows Notepad" and switch to Notepad++, Atom, Sublime, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM