awk -F : '$1 ~ /[[:digit:]]+[[:alnum:]]*[[:digit:]]+/ && ($3>6200) {print $5" --- "$1" --- "$3;count++} END{print"\n----------\nSuma znalezionych rekordów:"count"\n----------\n"}' /etc/passwd|iconv -f ISO8859-2 -t UTF-8

So my problem is that when I run the foregoing code in the terminal, iconv command converts the whole input from ISO8859-2 to UTF-8 and therefore - polish diactric signs are not printed correctly.

I changed the main encoding by adding LANG=pl_us.UTF-8 to .bashrc, so I suppose, that the problem appears because the file /etc/passwd is encoded in ISO8859-2 and the printed line is in UTF-8. How to fix that without any changes in .bashrc?

1 Answer 1


Instead of converting the mixed UTF-8 and ISO8859-2, convert the password file itself into UTF-8 and then apply your process

iconv -f ISO8859-2 -t UTF-8 </etc/passwd |
    awk -F: '
        $1 ~ /[[:digit:]]+[[:alnum:]]*[[:digit:]]+/ && ($3>6200) { printf "%s --- %s --- %s\n", $5, $1, $3; count++ }
        END { printf "\n----------\nSuma znalezionych rekordów:%d\n----------\n", count }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .