Tag Info

New answers tagged

0

Use the file command on Linux/Ubuntu. If the file is in DOS format, the output will include the words, "with CRLF line terminators". If the file is in UNIX format, no such words will be in the output. In the example, below, del.txt is in DOS format and del is in UNIX format. $ file del.txt del.txt: C source, ASCII text, with CRLF line terminators $ echo ...


0

Another perl approach. This one reads the entire input into memory so it might not be a good idea for large amounts of data (use cuonglm's or the awk approach for that): $ printf "one\ntwo\n" | perl -00pe 's/\n$//'; echo " done" one two done


0

The HTTP standard specifies that all header lines, as well as the empty line that marks the end of the headers, must use CRLF (carriage return, line feed) endings. A lot of clients are liberal and accept LF alone, but most servers, including Google, respect the standard. curl -I displays the headers exactly as sent by the server, including the CR ...


0

To apply the accepted answer to all files in the current directory (plus subdirectories): $ find . -type f -exec sed -i -e '$a\' {} \; This works on Linux (Ubuntu). On OS X you probably have to use -i '' (untested).


5

paste is probably the easiest (which is not to mention extremely efficient) means at your disposal to handle this problem. printf abc >file1 printf def >file2 paste -sd\\n file[12] abc def When paste is invoked -serially it will read each of its named input files in-turn and paste the output of each line within each file on either a <tab> or ...


1

It seems that your file1 has no trailing newline. If you want to concatenate a list of files. You can first check each one and cat a newline where needed, as follows: # make some sample files printf "%s\n" abc > file1 printf "%s" def > file2 # no trailing newline printf "%s\n" ghi > file3 printf "%s" jkl > file4 # no trailing newline ...


1

As Peter says, you first file does not have an end-of-line character. You can probably check it with ls -l --- if it's exactly three chars, this is it. If you want to "cat" the files adding a newline only if the newline wasn't there, you can use the nice trick explained here. If you have this three files: [romano:~/tmp] % ls -l f1 f2 f3 -rw-rw-r-- 1 ...


0

You have missing newlines. You could do cat file1; echo; cat file2; or create a file which has only one linebrake and do cat file1 NEWLINEFILE file2 or do this with a loop like this for i in find[1-2]; do cat $i; echo; done; to run through *, cat each file and add a newline afterwards. With $(find OPTIONS) instead of find[1-2], you could refine ...


1

Try this to remove carriage return: echo "$(curl -s -I https://google.com|grep Server)" abc | tr -d "\r" Output: Server: GFE/2.0 abc


2

echo $(curl -s -I https://google.com|grep Server)|cat -A shows that the value returned by curl has a ^M (a carriage return). When you print out the output of the curl, the carriage return takes the 'cursor' back to the start of the line, where it then prints out the ' abc', overwriting 'Serv'. In your second attempt, the carriage return has no obvious ...


5

Poking around with various inputs, I felt grep did its own magic for line-endings: $ printf "foo\rbar\n" | grep -oz $'\r' | od -c 0000000 \r \n 0000002 $ printf "foo\rbar\r\n" | grep -oz $'\r' | od -c 0000000 $ printf "foo\rbar\r" | grep -oz $'\r' | od -c 0000000 \r \n \r \n 0000004 (The -z was my lame attempt to make grep match everything.) And so ...



Top 50 recent answers are included