Answer the question
In order to leave comments, you need to log in
Linux has a locale.gen file. and strings like en_US.UTF-8 UTF-8. How can I split a string into 2 variables before a space and after?
The arch linux distribution has a locale.gen file. It contains lines of the form
ru_RU.UTF-8 UTF-8
en_US.UTF-8 UTF-8
zh_SG GB2312 The
question is to divide a string of this type into 2 variables, for example, zh_SG in one and GB2312 in another.
thanks for the help
Answer the question
In order to leave comments, you need to log in
Option 1
read the file line by line in a loop (while) read (read), and already in the loop we convert each line into variables like this:
$ LINE="zh_SG GB2312"
$ eval $(echo "$LINE" | awk '{print "var1="$1";var2="$2}')
we get:$ echo "$var1 $var2"
zh_SG GB2312
ru_RU.UTF-8 UTF-8
en_US.UTF-8 UTF-8
zh_SG GB2312
$ lines=(`cat lines.txt`)
$ echo ${lines[0]}
ru_RU.UTF-8
$ echo ${lines[1]}
UTF-8
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question