How to pipe tail -f to iconv cmmand?
Asked Answered
I

1

5

I have a log file encoding with gbk, I have to read the data like this:

tail -n 2000 nohup.out | iconv -f gbk -t utf-8

but when I use tail -f it will print nothing:

tail -f nohup.out | iconv -f gbk -t utf-8
Inaccurate answered 8/5, 2018 at 10:14 Comment(0)
P
8

In a similar situation I use a script that reads each line and convert. In your case: tail -f nohup.out | iconv.sh

#!/bin/bash
#iconv.sh
IFS=''
while read line
do 
    echo "$line" | iconv -f gbk -t utf-8
done  < "${1:-/dev/stdin}"
Polynesia answered 21/1, 2019 at 12:6 Comment(2)
This worked great for following a UTF-16 log generated by a Windows 10 PowerShell script from WSL Linux.Ewall
Better to buffer more lines at once: #8314999Meit

© 2022 - 2024 — McMap. All rights reserved.