Questions tagged [newlines]
Use for questions about representation and manipulation of the end-of-line marker in text files, in particular when editing the same file on different operating systems where the representation may vary.
317
questions
0
votes
0
answers
30
views
Why do newline characters get lost when concatenating strings ending with newline characters? [duplicate]
Scenario:
$ cat xxx.txt | od -c
0000000 x \n x \n
0000004
$ value=""
# 1st iteration
$ value+="$(<xxx.txt)" ; echo "$value" | od -c
0000000 x \n x \n
...
0
votes
1
answer
60
views
Redirect command output to file (append) and then append a newline character
I'm running the following one-liner:
cat input.txt | xargs -I{} bash -c './script.sh "{}"' >> output.txt
The script works and does exactly what I want it to do.
The only issue is that ...
0
votes
3
answers
765
views
How to convert CR to CRLF line endings on a file?
An ASCII text file, with CR line terminators, (Mac style) needs to be converted to have CRLF line terminators (DOS/Windows style).
Search for CR not followed by LF, and replace that CR with a CRLF. So ...
0
votes
2
answers
199
views
How to add an empty line after lines starting with a timestamp
The log viewing experience is so bad in my current company. I want to add new line to the logs that I've trimmed for a specific time duration. I want a new line after every date-time.
The date-time ...
0
votes
1
answer
256
views
"man cat" mentions "LFD." What is "LFD?"
man cat says:
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
I checked info cat, and it uses the same acronym:
‘-v’
‘--show-nonprinting’
Display ...
2
votes
3
answers
4k
views
How to deal with CRLF, CR line endings
I have a Perl script that parses data sent to me from a bunch of school districts. I'm adding a new school and have run into a problem I've never faced before. When I do $line = <INPUT>, it ...
2
votes
5
answers
241
views
How to remove newline characters inside paragraphs with sed or awk
I was wanting to know how to remove newline characters in paragraphs in this book and others for use in a kindle. The desired effect is to have each block that is separated by a blank line to be ...
10
votes
3
answers
2k
views
Add a CR before every LF
I have a text file being processed on a Windows machine. There is a need to remove trailing tab characters prior to using bcp utility to load the data from the file into a database table.
The ...
0
votes
1
answer
47
views
maintain appended logs in separate file despite tail command termination
I have tomcat catalina.log file that keeps getting updated.
I wish to maintain its past 500 lines + any appended logs into a new file catalina.log_new for the next 2 hours.
To start off I run nohup ...
0
votes
1
answer
73
views
How to find and manipulate files that contain newline in filename?
follow up on How to find files that contain newline in filename? ,
I need to do some manipulation on the result, for simplicity lets suppose I need to chown them.
Tried following, but does not work:
# ...
-1
votes
1
answer
309
views
Newline character '\n' (return key) in *nix!
While studying Linux, I noticed that the newline character is used not only to separate different lines - that is to set the beginning and the end of a line - but also is used to give some input to ...
0
votes
1
answer
137
views
grep searching end of line pattern from DOS files
Like Detecting pattern at the end of a line with grep, but for DOS files of CRLF line terminators.
Like in https://unix.stackexchange.com/a/462633/374303, one way is to use dos2unix but I don't have ...
2
votes
2
answers
298
views
Do executable shebang scripts always require LF line endings?
On Stack Overflow a comment to Can PowerShell Core handle ps1 files with CRLF line endings in Linux environments? asserted that executable files that use a shebang must use only the LF line ending, ...
0
votes
1
answer
108
views
GNU sed: append both BEFORE name start and AFTER name end (output is: "$ ls -xN")
Please could someone check if my GNU sed script is the nice way to do it or if it's some sort of bad / wrong hack :p
$ ls -xN
1
2
3
4
$ ls -xN | sed -E "s/(.{1})$/\1\.log/" | sed -E "s/...
0
votes
1
answer
235
views
MacOS append char at end of line with sed
I'm on MacOS where I want to enclose field names by "" in the header. Reading the file with sed, I use this command
sed -i.bkp -e '1s/,/","/g' -e '1s/.*/"&/g' -e '1s/.*/&...