To sum several values in column from file we can use paste command and bash arithmetic expressions
$ echo $(($(paste -s -d'+' nums)))
I've always used tr to glue the values into one line, but the remaining '+' sign must be removed:
$ echo $(($(cat nums | tr '\n' '+' |sed 's/.$//')))
Or with awk:
$ awk '{s+=$1}; END { print s}' nums
Showing posts with label tr. Show all posts
Showing posts with label tr. Show all posts
Thursday, November 17, 2016
Saturday, July 16, 2016
wget and line delimiters CR LF
If you download file with wget and the filename comes from windows file, the output filename will always have %0D at the end. To get rid of this, instead of:
wget $filename
use
wget $(echo "$filename" | tr -d '\r')
This will do the trick
wget $filename
use
wget $(echo "$filename" | tr -d '\r')
This will do the trick
Etykiety:
cr,
end of line,
tr,
wget
Tuesday, August 25, 2009
Generating strong passwords
Sometimes we need to make up the password. Normally the password should be easy to remember but hard to guess. I show you how to generate strong passwords that are not easy to remember :). We'll use for this purpose /dev/urandom device, which generates random data. Suppose we want to generate 10 passwords, each 8 characters long. To achieve this we type:
$ cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -8 | head -10
lUrBzyuv
RuDq498i
mOzJMs4Y
s0lUpMZd
LmwuN6Sy
fubIOO6g
KKynsPs4
dFH4W0Ux
3JAbwJQD
PofhRhTS
The fold command breaks each line after n characters, so defines the length of the password, the head command shows first n lines so defines the number of passwords. The tr deletes (-d) all but specified (-c) characters. The idea comes from here.
$ cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -8 | head -10
lUrBzyuv
RuDq498i
mOzJMs4Y
s0lUpMZd
LmwuN6Sy
fubIOO6g
KKynsPs4
dFH4W0Ux
3JAbwJQD
PofhRhTS
The fold command breaks each line after n characters, so defines the length of the password, the head command shows first n lines so defines the number of passwords. The tr deletes (-d) all but specified (-c) characters. The idea comes from here.
Subscribe to:
Posts (Atom)