In Bash, you can read the file test.txt and output its contents as a single string with newlines represented as \n using the following command:
bashawk '{printf "%s\\n", $0}' test.txt | tr -d '\n'
awk '{printf "%s\\n", $0}' test.txt: This prints each line followed by a literal \n (not a newline character).tr -d '\n': This removes the actual newline characters that awk would otherwise output.For your test.txt file, this will output:
texta\nb\nc
Alternatively, you can use paste and sed:
bashpaste -sd '\\n' test.txt
This will also produce:
texta\nb\nc
Vibe can make mistakes. Check answers. Learn more