The tag has no usage guidance.

learn more… | top users | synonyms

15
votes
3answers
11k views

Finding all “Non-Binary” files

Is it possible to use the find command to find all the "non-binary" files in a directory? Here's the problem I'm trying to solve. I've received an archive of files from a windows user. This archive ...
7
votes
1answer
837 views

shebang line not working with cr-lf

Why are the shebang parts of the following elementary scripts not working: $ cat hello.sh #! /bin/sh echo Hello $ ./hello.sh bash: ./hello.sh: /bin/sh^M: bad interpreter: No such file or directory $ ...
1
vote
0answers
25 views

incrontab on folder name containing line feeds

I'm writing a script searching for directories in a subtree and appending them to incrontab. I can even add folder names with blanks by escaping those with a backslash: /path/to/observed\ directory ...
18
votes
7answers
28k views

How to test whether a file uses CRLF or LF without modifying it?

I need to periodically run a command that ensures that some text files are kept in Linux mode. Unfortunately dos2unix always modifies the file, which would mess file's and folder's timestamps and ...
0
votes
0answers
24 views

How to match Markdown Setext headers in in exuberant ctags

I am working on a language definition for pandoc markdown in ctags. However, I have problems matching Setext headers in the regex which are defined by multiple = or - in a new line under the header ...
1
vote
1answer
56 views

Adding/removing some tabs and line breaks in an HTML code using sed

I want to refine an HTML code using sed, as an extra refinement procedure after refining it using HTML Tidy, as HTML Tidy doesn’t look flexible enough for some requirements. I used this command to ...
2
votes
4answers
65 views

Can Awk read escaped newlines? I.e. read past newlines

I have input looking like this: entry1line1 entry2line1\ entry2line2\ entry2line3 entry3line1 I would like to read such input into an array in AWK, to then process it together with the embedded ...
1
vote
0answers
52 views

Can minicom translate incoming newline (\n) to CR+LF?

I have a micro-controller device that is sending newline-terminated strings through the USB-attached serial port and (so far) I'm using minicom version 2.6 to read from /dev/ttyACM0. I've setup the ...
1
vote
0answers
42 views

What are newline rules in Bash? [closed]

I have very long commands, I want to beautify the reading of the commands using linebreaks. What are some good line-break using \ rules in Bash? I know, I should never follow the \ with a space. ...
2
votes
0answers
25 views

Sometimes my zsh messes the end of lines

I have this strange issue, that I cannot find the source of, nor a solution to solve. "Sometimes" my zsh gets messed up and start display end of lines in a funny way: As you can see, the newlines ...
2
votes
3answers
46 views

Bash read with delimiter past newlines

I have a csv for which I have to extract a specific field. The csv is pipe-delimited (|), with double quotes (") to protect text fields and (this is the catch) newlines in some of the text. eg. "aaa"...
0
votes
2answers
46 views

Carriage returns are prevent sed reading all my files

I have a long list of folders, inside every folder I have the file "log.dat". I wanted to read the value of a specific line inside this file. I saved the folders names in a file "All.txt", in the ...
2
votes
2answers
74 views

bash read of a newline, printf reports character 0

I use bash printf function to print ASCII codes of characters in an input file, but for some reason printf outputs ascii code 0 for LF characters, instead of 10. Any ideas why? while IFS= read -r -n1 ...
1
vote
0answers
47 views

Bash scripts not found. Maybe EOL issue? [closed]

I am facing a problem that is driving me crazy. In the past months I have been developing a project based on a Linux distribution (Openwrt) that has been recently updated. My project has a lot of bash ...
3
votes
1answer
3k views

How to fix “Hunk #1 FAILED at 1 (different line endings)” message?

I am trying to create a patch with the command git diff sourcefile >/var/lib/laymab/overlay/category/ebuild/files/thepatch.patch when I apply the patch, it gives me $ patch -v GNU patch 2.7.5 ...
1
vote
3answers
190 views

How to break a long string into multiple lines in the prompt of read -p within the source code?

I am writing an installation script that will be run as /bin/sh. There is a line prompting for a file: read -p "goat can try change directory if cd fails to do so. Would you like to add this feature?...
9
votes
4answers
34k views

How to add a carriage return before every newline?

I have a file that only uses \n for new lines, but I need it to have \r\n for each new line. How can I do this? For example, I solved it in Vim using :%s/\n/\r\n/g, but I would like to use a script ...
1
vote
1answer
81 views

How can my text file get filled with ^M characters all of a sudden?

I have a text file on a Mac machine, and I've only ever used vi/vim to edit it. Today when I opened it using vi I noticed a bunch of ^M characters everywhere. The only thing I did different today was ...
3
votes
1answer
673 views

Why is the end-of-line $ anchor not working with the grep command, even though the front-of-line ^ anchor is?

Very new to UNIX but not new to programming. Using Terminal on MacBook. For the purposes of managing and searching word lists for crossword construction, I'm trying to get handy with the Grep command ...
15
votes
2answers
2k views

Why doesn't the Enter key send EOL?

Unix / Linux EOL is LF, linefeed, ASCII 10, escape sequence \n. Here's a Python snippet to get exactly one keypress: import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(...
93
votes
14answers
107k 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 of those messages?
1
vote
3answers
69 views

Remove forced line breaks from fortune output while preserving them for the author line

Recently I encountered the great fortune command and use it now to send a nightly quote to a persistent chat. Now I wonder how to remove the forced line breaks for the quote part, but preserve them ...
10
votes
6answers
44k 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
4answers
16k views

Remove ^M character from log files

Remove ^M character from log files. In my script I redirect output of my program to a log file. The output of my log file contains some ^M (newline) characters. I need to remove them while running ...
10
votes
5answers
17k views

How to put a newline special character into a file using the echo command and redirection operator?

I would like to create a file by using the echo command and the redirection operator, the file should be made of a few lines. I tried to include a newline by "\n" inside the string: echo "first ...
5
votes
2answers
131 views

How to insert newlines into PATTERN when using fgrep / grep -F / grep --fixed-strings

When using fgrep, the man page says it will Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. In bash, what's the correct way to insert ...
3
votes
3answers
215 views

How do I remove newline character at the end of file?

Let me clear about newline character: $ echo Hello > file1 ; cat file1 Hello $ echo -n Hello > file2 ; cat file2 Hello$ Here you can see that file1 has newline character at the end whereas ...
0
votes
2answers
36 views

Shell script - blanks are not always recognized as such?

I'm confused on how bash interprets blanks while executing a script. In the end, I want a script that is fed by a csv file containing software used by an organisation and it should return the CVEs for ...
6
votes
1answer
65 views

How can I make `file` output line break type and encoding for all file types?

I often find myself in the need to check the encoding and the line break type of a file. The file utility seems to be a perfect fit. Unfortunately it doesn't output the desired information for all ...
1
vote
2answers
90 views

How to preserve the carriage return character (\n) when capture output of a command in a variable

As a simple example, I have a bunch of source code files. I want to store the "head" command output to a variable for all these files. I tried: output=$(head $file) but what happened is that this ...
1
vote
1answer
43 views

Why CR sequence (\r) getting entered in .vimrc file?

Please look at my '~/.vimrc' file below. :map g :w :map g :w See, the same line repeated. After writing 1st line, I pressed the "Enter" key. Now see the output of the od command below. ravi@ravi-...
0
votes
2answers
90 views

Check whether a file uses CRLF or LF to end lines [duplicate]

How to check whether lines in a text file end with CRLF or LF?
7
votes
4answers
11k views

Replace \n by a newline in sed portably

I'm so confused with GNU sed, POSIX sed, and BSD sed's myriad of options. How do I replace literal \n with the newline character using these three sed types?
1
vote
1answer
128 views

How can I replace a literal \n with a newline character? (on OS X) [duplicate]

I have a script which pulls something out of my shell history and saves it to a file, but if there is a newline in the history entry it gets returned to me with a literal \n instead of the newline ...
2
votes
1answer
34 views

Regex to match = followed by a newline so they both be deleted

I am working with the raw source content of a mail.app message in OSX, but results it gives me the text in quoted printable MIME Email encoding. so I need to remove all those strange characters to get ...
3
votes
2answers
2k 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 ...
1
vote
5answers
66 views

can't remove file with carriage returns

I have a file blahblah\r\n.txt that I want to remove but rm blahblah\r\n.txt does not work as I receive No such file or directory message. How to remove??
3
votes
4answers
129 views

Not able to cat a string from a file under a string of another file

I have encountered a strange issue in concatenating the files using the cat command. I have two files with one string in each of them: file1: ABC file2: DEF Either I do cat file1 file2 or ...
8
votes
6answers
534 views

Force newlines with cat wildcard printing

I want to use cat with wildcards in bash in order to print multiple small files (every file is one sentence) to standard output. However, the separate file contents are not separated by a newline, ...
1
vote
0answers
223 views

Grep can't find end of line in DOS format text file?

In Ubuntu I'm working on a C file that was originally created under Windows and then committed to source control. Vim shows the file format is "dos", which I gather just means it has CR/LF line ...
2
votes
3answers
173 views

uniq showing duplicate lines

$ grep home american.txt | sort | uniq A home and a country should leave us no more! ...
6
votes
5answers
1k views

Remove backslash + newline sequences

We are having a file in Linux which contains one line per record, but problem comes when the line contains some new line characters. In this case, the backslash is appended at the end of line and the ...
0
votes
4answers
240 views

How to delete the newline before EOF in a text/csv file via bash

Below is an example of the data I'm receiving in txt or csv file (seen in EmEditor): However, the final blank line is causing problems when uploading this data into my software. I need to have the ...
74
votes
5answers
26k 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
1answer
152 views

bash prevent printf from interrupting another printf

I have the following test script. #!/bin/bash function foo { printf "Test line break: $1\nafter line break\n\n" } for VARIABLE in {1..30} do foo $VARIABLE & done wait Now I executed the ...
0
votes
1answer
48 views

How do I correctly add line ends with sed? [closed]

I have several sed statements that at one points uses newlines in the output with \n (Actually they are sed's using $' with \\\n's`). However subsequent sed operations that wish to operate on the end ...
2
votes
1answer
151 views

adb pull not accepting a variable as source, gives *' does not exist..* error

I'm trying to use $EXTERNAL_STORAGE in the adb pull command. I noticed that the variable has its scope defined in Android only and so it would not work successfully in adb pull $EXTERNAL_STORAGE/...
0
votes
1answer
97 views

How to replace \1\ with new line

I have a record like: "evSchema"\1\"UAT" "evSN"\1\"uadb" "evDirsep"\1\"/" "evRootPath"\1\"/work_area/APP_UAT/" "evSchema"\1\"RMS13" "evUser"\1\"STAGE" I want to replace \1\ with new line. I tried ...
1
vote
1answer
2k views

'while read line do' cause: “syntax error near unexpected token `done'” in Linux bash script

I have a shell script which is running fine on Solaris platform but not working on Linux platform. The Failing code snippet is as following: [...] while read line do insert_into_table="insert into ...
0
votes
1answer
1k views

How to add new line in text file in output from remote shell script using plink

From windows i am executing a remote shell script using putty plink cmd>plink.exe -ssh username@hostipd -pw gbG8qs4 /user/alice/listoffiles.sh > C:\log1.txt Shell script in remote server #! ...