Why does Spanish locale sort order differ between CentOs 6.9 and Ubuntu 18.04? - locale

Does anybody have a good explanation why Spanish locale sort order differs between CentOs 6.9 and Ubuntu 18.04:
On CentOS release 6.9:
$ export LC_COLLATE=es_ES.utf8
$ echo "niño ninja ninus" | tr ' ' '\n' | sort
ninja
niño
ninus
And on Ubuntu 18.04
$ export LC_COLLATE=es_ES.utf8
$ echo "niño ninja ninus" | tr ' ' '\n' | sort
ninja
ninus
niño
So in Centos6.9 "niño" is sorted before "ninus" while Ubuntu 18.04 reverses that order.

Related

Getting OS name and version from Linx os-release file

I'm attempting to get the OS name (pretty_name)and version (version_ID) on one line via the /etc/os-release file, in a simple command.
Currently, I have the following:
cat /etc/*-release | egrep "PRETTY_NAME|VERSION_ID" | cut -d = -f 2 | tr -d '"'
Which gives me the following output:
7.9
Red Hat Enterprise Linux
I'm looking to get my output looking like this:
Red Hat Enterprise Linux 7.9
What can I do to get the output the way I want it to be?
Since os-release is in shell format (and provided by your OS vendor, whom you're obliged to trust), you can just source it (which treats the quotes as syntax rather than data, so they don't need to be manually removed).
Amending to follow the advice from #Cyrus to prefer Red Hat's extended metadata over the generic variable names when available (but falling back to the generic names otherwise):
. /etc/os-release
printf '%s %s\n' \
"${REDHAT_SUPPORT_PRODUCT:-$PRETTY_NAME}" \
"${REDHAT_SUPPORT_PRODUCT_VERSION:-$VERSION_ID}"
Note; the order of the contents of /etc/*-release can't be guaranteed. This answer focus on OP's case;
Use tac to reverse the output, then use tr '\n' ' ' to concatenate the lines;
cat /etc/*-release | egrep "PRETTY_NAME|VERSION_ID" | cut -d = -f 2 | tr -d '"' | tac | tr '\n' ' '
# 10 Debian GNU/Linux 10 (buster)
Another option would be to read the second and third line of lsb_release witch has a more consistent output;
lsb_release -as 2>/dev/null | sed -n 2,3p | tac | tr '\n' ' '
# 10 Debian GNU/Linux 10 (buster)

How to parse the correct version number?

The command below will return the corresponding strings
$ docker-compose exec postgres postgres --version
postgres (PostgreSQL) 10.4 (Debian 10.4-2.pgdg90+1)
I am trying to get the postgresql version but when I tried, the Debian version and other numbers are included like
$ pg_version=$(docker-compose exec postgres postgres --version | sed 's/[^0-9.]//g')
10.410.42.901
I am wondering how to get the 10.4 only
awk -v RS=" " '/^[0-9.]+$/{print; exit}'
grep -oE '[.0-9]+' | head -1
tr ' ' '\n' | grep -oE -m 1 '[.0-9]+'
sed 's|^[^0-9.]*\([0-9.]\+\).*|\1|'
Modify the sed as followed would help,
sed -E 's/.*PostgreSQL[^0-9.]+([0-9.]*).*/\1/'
\1 would only match to the version number right behind "PostgreSQL".
pg_version=$(docker-compose exec postgres postgres -V | grep -oE '[.0-9]+' | head -1)
You could use grep with something like this:
$ grep -oP "PostgreSQL.\s\K.+?(?=\s)"
For example:
$ echo "postgres (PostgreSQL) 10.4 (Debian 10.4-2.pgdg90+1)" | grep -oP "SQL.\s\K.+?(?=\s)"
10.4
The \K can be read as excluding everything to the left *SQL)<space> before it and return only the right part .+?(?=\s) until and space \s is found.

How to find/list packages by number of dependencies using apt?

I installed a command line video game emulator on a media server running Ubuntu 14.04.2 LTS a long time ago and I can't remember what it was called.. I only remember that it had a ton of dependencies.. I'm trying to clean up that server now and I'm wondering if there's any way to somehow list packages by number of dependencies? Where is that information stored in apt/aptitude/ubuntu? Is there a better way to go about this?
dpkg --get-selections | grep -v deinstall | awk '{print $1}' | xargs apt-cache depends | awk '/^ / {count++} /^[^ ]/ {print count " " $1; count = 0}' | sort -V

How to fetch Java version using single line command in Linux

I want to fetch the Java version in Linux in a single command.
I am new to awk so I am trying something like
java -version|awk '{print$3}'
But that does not return the version. How would I fetch the 1.6.0_21 from the below Java version output?
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)
Redirect stderr to stdout.
Get first line
Filter the version number.
java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}'
This is a slight variation, but PJW's solution didn't quite work for me:
java -version 2>&1 | head -n 1 | cut -d'"' -f2
just cut the string on the delimiter " (double quotes) and get the second field.
I'd suggest using grep -i version to make sure you get the right line containing the version string. If you have the environment variable JAVA_OPTIONS set, openjdk will print the java options before printing the version information. This version returns 1.6, 1.7 etc.
java -version 2>&1 | grep -i version | cut -d'"' -f2 | cut -d'.' -f1-2
Since (at least on my linux system) the version string looks like "1.8.0_45":
#!/bin/bash
function checkJavaVers {
for token in $(java -version 2>&1)
do
if [[ $token =~ \"([[:digit:]])\.([[:digit:]])\.(.*)\" ]]
then
export JAVA_MAJOR=${BASH_REMATCH[1]}
export JAVA_MINOR=${BASH_REMATCH[2]}
export JAVA_BUILD=${BASH_REMATCH[3]}
return 0
fi
done
return 1
}
#test
checkJavaVers || { echo "check failed" ; exit; }
echo "$JAVA_MAJOR $JAVA_MINOR $JAVA_BUILD"
~
You can use --version and in that case it's not required to redirect to stdout
java --version | head -1 | cut -f2 -d' '
From java help
-version print product version to the error stream and exit
--version print product version to the output stream and exit
Here's my variation (with thanks/acknowledgements to many answers prior to this). My goal is to produce a "Major Version" in line with JEP 223. Assumption are made; I don't know if it works across the board for all released (or to be released) versions of java.
java -version 2>&1 | fgrep -i version | cut -d'"' -f2 | sed -e 's/^1\./1\%/' -e 's/\..*//' -e 's/%/./'
Version
Results
1.6.0_65
1.6
1.8.0_282
1.8
11.0.10
11
15.0.2
15
This way works for me.
# java -version 2>&1|awk '/version/ {gsub("\"","") ; print $NF}'
1.8.0_171
Getting only the "major" build #:
java -version 2>&1 | head -n 1 | awk -F'["_.]' '{print $3}'

Locate CUDA installation on Linux

What's the best way?
Here are my solutions:
echo $PATH | sed "s/:/\n/g" | grep "cuda/bin" | sed "s/\/bin//g" | head -n 1
which nvcc | sed "s/\/bin\/nvcc//"
which nvcc | head -c -10
They are all PATH-based. One could locate libraries instead.
It would be more robust if there are no CUDA paths in PATH.
I'm using this in a Makefile.
How does something based onldconfig -p | grep libcuda sound ? Considering an appropriate ldconfig setup is explicitly advised at the end of the installation of the CUDA toolkit, it should do the trick without path nicely, I think.

Resources