Linked Questions

25
votes
6answers
52k views

Difference between printf and echo in bash [duplicate]

What is the difference between the printf function in bash and the echo function? Specifically, running: echo "blah" >/dev/udp/localhost/8125 did not send the "blah" command to the server ...
0
votes
0answers
293 views

echo -n option not working [duplicate]

New to shell scripting, I wanted to learn how the echo command works. I started with the following code. echo -n "What is your name -- " read i echo "Your name is $i" I do not understand why I ...
352
votes
4answers
114k views

What does “--” (double-dash) mean? (also known as “bare double dash”)

I have seen -- used in the compgen command. For example: compgen -W "foo bar baz" -- b What is the meaning of the -- in there?
73
votes
18answers
183k views

How to count the number of a specific character in each line?

I was wondering how to count the number of a specific character in each line by some text processing utilities? For example, to count " in each line of the following text "hello!" Thank you! The ...
53
votes
8answers
57k views

How to delete line with echo?

I know that I could delete the last three chars with: echo -ne '\b\b\b' But how can I delete a full line? I mean I don't want to use: echo -ne '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\...
15
votes
15answers
30k views

'ls -1' : how to list filenames without extension

ls -1 lists my elements like so: foo.png bar.png foobar.png ... I want it listed without the .png like so: foo bar foobar ... (the dir only contains .png files) Can somebody tell me how to use ...
40
votes
6answers
124k views

Concatenating two variables with an underscore

I need to concatenate two variables to create a filename that has an underscore. Lets call my variables $FILENAME and $EXTENSION where filename is read from a file. FILENAME=Hello EXTENSION=WORLD.txt ...
31
votes
6answers
103k views

How to add new lines when using echo

Why the following command does not inserts new lines in the generated file and what's the solution? $echo "Line 1\r\nLine2" >> readme.txt $ cat readme.txt Line 1\r\nLine2
29
votes
7answers
87k 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 ...
27
votes
5answers
110k views

Redirecting the content of a file to the command “echo”

I have a file named my_file.txt whose content is just the string Hello. How could I redirect its content to the command echo? I know I have the commands less, cat, more... but I need to do it with ...
21
votes
6answers
2k views

Is there another simple way to append line to end of file other than `>>`?

Recently I'm echoing short sentences to a tree_hole file. I was using echo 'something' >> tree_hole to do this job. But I was always worried of what if I mis-input of > instead of >>, ...
10
votes
8answers
2k views

How to remove line if it contains a character exactly once

I want to remove a line from a file which contains a particular character only once, if it is present more than once or is not present then keep the line in file. For example: DTHGTY FGTHDC HYTRHD ...
21
votes
5answers
1k views

How can I find the common name for a particular glyph?

Sometimes, I'd like to know the name of a glyph. For example, if I see −, I may want to know if it's a hyphen -, an en-dash –, an em-dash —, or a minus symbol −. Is there a way that I can copy-paste ...
13
votes
9answers
2k views

Command line tool to “cat” pairwise expansion of all rows in a file

Suppose I have a file (call it sample.txt) that looks like this: Row1,10 Row2,20 Row3,30 Row4,40 I want to be able to work on a stream from this file that is essentially the pairwise combination of ...
14
votes
6answers
4k views

Why there is such a difference in execution time of echo and cat?

Answering this question caused me to ask another question: I thought the following scripts do the same thing and the second one should be much faster, because the first one uses cat that needs to open ...

15 30 50 per page