Linked Questions

41
votes
4answers
90k 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 ...
10
votes
6answers
6k 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 ...
9
votes
4answers
2k 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' \ # ...
6
votes
4answers
6k 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 *....
2
votes
2answers
5k 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
2answers
4k 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. ...
3
votes
4answers
319 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 ...
1
vote
4answers
950 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
105 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
48 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 ...