Linked Questions

35
votes
6answers
72k 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
50 views

Need complete output into variable in bash [duplicate]

Following is the command which is in shell script. var="$(sshpass -p 'password' ssh -o "StrictHostKeyChecking=no" username@hostip <<-EOF command to run on remote host EOF )" when i echo $var, ...
0
votes
0answers
28 views

Avoiding echo -e [duplicate]

I would like to store an HTTP request in a variable and then use it with OpenSSL I now have HTTP_REQUEST="HEAD / HTTP/1.1\\nHost: ${HOST_HEADER}\\nUser-Agent: check_ssl_cert/${VERSION}\\nConnection: ...
436
votes
4answers
151k 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?
81
votes
18answers
209k 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 ...
58
votes
8answers
69k 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\...
19
votes
15answers
39k 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 ...
50
votes
6answers
146k 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 ...
42
votes
6answers
146k views

How to add new lines when using echo

Why does the following command not insert 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
34
votes
7answers
108k 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 ...
24
votes
8answers
2k views

Is piping, shifting, or parameter expansion more efficient?

I'm trying to find the most efficient way to iterate through certain values that are a consistent number of values away from each other in a space separated list of words(I don't want to use an array)....
35
votes
5answers
151k 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 ...
7
votes
5answers
3k views

How to list *.tar.gz, one filename per line?

I am trying to list every .tar.gz file, only using the following command: ls *.tar.gz -l ...It shows me the following list: -rw-rw-r-- 1 osm osm 949 Nov 27 16:17 file1.tar.gz -rw-rw-r-- 1 osm osm ...
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 ...

15 30 50 per page