Linked Questions

685 votes
4 answers
301k views

Why is printf better than echo?

I have heard that printf is better than echo. I can recall only one instance from my experience where I had to use printf because echo didn't work for feeding some text into some program on RHEL 5.8 ...
  • 12.1k
74 votes
4 answers
181k 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 ...
  • 1,119
47 votes
4 answers
59k 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?
  • 863
30 votes
7 answers
27k 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 ...
  • 95.9k
23 votes
5 answers
26k 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 *....
13 votes
3 answers
5k 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 '*....
  • 9,312
5 votes
4 answers
10k 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' \ # ...
7 votes
2 answers
531 views

What is this sed doing with the script: `$a\`?

I've come upon this sed command and I cannot figure out what it is doing. I understand that it is changing a file in place using -i, that it is using a script -e and that the script is $a\, but what ...
6 votes
3 answers
3k 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 ...
2 votes
3 answers
13k 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 ) | ...
  • 21
0 votes
1 answer
14k 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. ...
  • 11.2k
2 votes
4 answers
7k 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 ...
  • 93
3 votes
5 answers
851 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 ...
  • 161
4 votes
2 answers
465 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, ...
2 votes
1 answer
1k 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 ...
  • 5,239

15 30 50 per page