Linked Questions

56
votes
4answers
120k views

echo bytes to a file

I'm trying to connect my rasberry Pi to some display using the i2c bus. To get started I wanted to manually write stuff, bytes in particular to a file. How do you write specific bytes to a file? I ...
39
votes
4answers
44k views

What does the noeol indicator at the bottom of a vim edit session mean?

I opened a file using vim on Ubuntu, and the following is displayed at the bottom of the screen: "file.py" [noeol] 553L, 16620C What does noeol indicate?
14
votes
6answers
13k views

Read a line-oriented file which may not end with a newline

I have a file named /tmp/urlFile where each line represents a url. I am trying to read from the file as follows: cat "/tmp/urlFile" | while read url do echo $url done If the last line doesn't ...
10
votes
5answers
12k views

How to cat files together, adding missing newlines at end of some files

I have a bunch of .text files, most of which end with the standard nl. A couple don't have any terminator at end. The last physical byte is (generally) an alphameric character. I was using cat *....
10
votes
4answers
3k views

How to find files that don't have empty line at the end?

I have files in subdirectories of the current directory that may or may not have new lines at the end; how can I find files that don't have a newline at the end? I've tried this: find . -name '*....
5
votes
5answers
8k views

Using sed, how to format one word per line, removing white space

I'm trying to replaces patterns and cleanup a file containing multiple words to get one word per line. The result is achieved using this command line: sed -e '/^[[:space:]]*$/ d' \ # ...
2
votes
2answers
7k views

UNIX: Need to replace last line on the file and also remove extra blank line in the end

I need to replace - WOR to VWOR in end of the file. I have tried sed s/WOR/VWOR/g But this does not work until I have new blank line in file. So I used ( cat FileName && echo ) | ...
0
votes
1answer
7k views

while read loop stops after the first line even though it doesn't read from stdin [closed]

I have a file called test containing test test and I am running this command while read line do echo "$line" done </tmp/test This should output "test" two times but it only outputs it once. ...
4
votes
2answers
347 views

Is there a way to count the number of lines of text in a file including non-delimited ones?

The POSIX wc command counts how many POSIX lines in a file. The POSIX standard defines a line as a text string with the suffix \n. Without \n, a pure text string can't be called a line. But to me, ...
3
votes
4answers
451 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 I ...
4
votes
3answers
434 views

Determine whether a file has no EOL at the end from the command line

If you open a file in vim and that file has no EOL at the end of its last line, then the editor will report it as [noeol]. How can I determine this before opening it in vim? (Is there a command I can ...
1
vote
4answers
2k views

Treat “\r” as nothing in “while read -r”

I have this line of code that reads a text file line by line. The text file is sometimes generated by a Windows user, sometimes by a Unix user. Therefore, sometimes I see \r\n at the end of the line ...
2
votes
1answer
364 views

Should the last line in a configuration file have a newline after it?

I sometimes whether I should put a newline after the last line in a configuration file, especially if it is a one-line configuration file, like the hostname file. Does it not matter, or is there a ...
0
votes
3answers
57 views

new line not append instead append on the end of the line

we gave the following config file ( config.txt ) more config.txt export var1=345476746 but when I am appending new parameter as echo "export var2=5645" >> config.txt we get more config.txt ...