The tag has no wiki summary.

learn more… | top users | synonyms

41
votes
4answers
8k views

What's the point in adding a new line to the end of a file?

Some compilers (especially C or C++ ones) give you warnings about: No new line at end of file I thought this would be a C-programmers-only problem, but github displays a message in the commit view: ...
4
votes
2answers
10k views

Can sed replace new line characters?

Is there an issue with sed and new line character? I have a file test.txt with the following contents aaaaa bbbbb ccccc ddddd The following does not work: sed -r -i 's/\n/,/g' test.txt ...
3
votes
3answers
2k views

How to bulk convert all the file in a file system branch between Unix and Windows line break format?

Everybody knows :-) that in Windows plain text files lines are terminated with CR+LF, and in Unix&Linux - with LF only. How can I quickly convert all my source code files from one format to ...
2
votes
2answers
218 views

Directories are listed twice

I have something odd. I creates some directories using a very simple script : ... create all directories ( running under a user that has the correct rights ) e.g : mkdir -p ...
2
votes
5answers
5k views

Carriage return issue

I have this in a bash script DAY2="20130605"<Cr> echo "This is yesterday date:"$DAY2"end" Why is the output the following? It seems as though there is a carriage return in DAY2 but where is ...
0
votes
1answer
3k views

Script failing with “command not found: ^M”

When I try to run the following script in zsh, via the command /bin/zsh ~/.set_color_scheme.sh I get the following error: command not found: ^M The script has u+x permissions and it used to work on ...
48
votes
7answers
48k views

How to add a newline to the end of a file?

Using version control systems I get annoyed at the noise when the diff says No newline at end of file. So I was wondering: How to add a newline at the end of a file to get rid off those messages?
13
votes
8answers
2k views

Replace string containing newline in huge file

Anyone know of a non-line-based tool to "binary" search/replace strings in a somewhat memory-efficient way? See this question too. I have a +2GB text file that I would like to process similar to what ...
5
votes
5answers
212 views

Automatic transformation of newlines in shell variable assignment

This came out of one of my comments to this question regarding the use of bc in shell scripting. bc puts line breaks in large numbers, e.g.: > num=$(echo 6^6^3 | bc) > echo $num ...
5
votes
3answers
364 views

Remove trailing new line from 'clipboard' to prevent execution on the terminal?

Is there some way to run whatever you copy to the 'clipboard' through some sort of filter? Ideally to strip out the trailing newline from something you copy, so that it doesn't auto-run in the ...
4
votes
3answers
546 views

How to skip file in sed if it contains regex?

I currently use the following simplified command to remove trailing whitespace and add a newline at end of file where needed: find . -type f -exec sed -i -e 's/[ \t]\+\(\r\?\)$/\1/;$a\' {} \+ As ...
2
votes
2answers
580 views

Shell script works when saved with nano but not when saved with Notepad++

I've been working on a bash script all day and have been testing on the machine I will be using it on. When I copy the script across from Notepad++ into a new file with nano editor inside SSH and ...
2
votes
2answers
251 views

Removing consecutive newlines with ed

Input file: 1 line1\ 2 line2\ 3 line3\ 4 \ 5 line4\ 6 \ 7 \ 8 line5\ Desired output: 1 line1 2 line2 3 line3 4 5 line4 6 7 line5 Is it possible with POSIX ed? Removing the trailing backslashes ...
1
vote
1answer
605 views

sed: N command does not read single line

Why sed's N command does not read single line? # single line without \n $ echo -en 'abc' | sed -n 'N;p' $ # I expected 'abc' # single line with \n $ echo -en 'abc\n' | sed -n 'N;p' $ # I expected ...