BAEL-3474: Appending multiple lines to a file

This commit is contained in:
Rens Verhage 2019-11-18 19:16:09 +01:00
parent 7d52a39289
commit 699d153da0
2 changed files with 31 additions and 0 deletions

View File

@ -1,3 +1,5 @@
### Relevant Articles:
- [Linux Commands Remove All Text After X](https://www.baeldung.com/linux/remove-text-after-x-in-file)
- [Linux Commands - Appending Multiple Lines to a File](https://www.baeldung.com/linux/appending-multiple-lines-to-a-file)

View File

@ -0,0 +1,29 @@
#!/bin/bash
# echo per line
echo Lorem ipsum dolor sit amet, consectetur adipiscing elit, >> echo-per-line.txt
echo sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. >> echo-per-line.txt
# echo with escaped newline
echo -e Lorem ipsum dolor sit amet, consectetur adipiscing elit,\\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua. >> echo-escaped-newline.txt
# echo with double quoted string
echo -e "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua." >> echo-double-quoted.txt
# printf instead of echo
printf "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua." >> printf.txt
# printf using format string
printf "%s\n%s" "Lorem ipsum dolor sit amet, consectetur adipiscing elit," "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." >> printf-format.txt
# cat
cat << EOF >> cat.txt
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
EOF
# tee
tee -a tee.txt << EOF
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
EOF