Yad(又一个对话框)列出了专栏

时间:2014-01-21 13:16:25

标签: bash shell user-interface scripting yad

我需要YAD的帮助。所以这是代码:

contact=$(while read line
            do
                firstname=$(echo $line | awk 'BEGIN { FS="|" } { print $2 }')
                lastname=$(echo $line | awk 'BEGIN { FS="|" } { print $3 }')
                num=$(echo $line | awk 'BEGIN { FS="|" } { print $4 }')
                birthday=$(echo $line | awk 'BEGIN { FS="|" } { print $5 }')

                if [  $firstname != ""  -a  $lastname != "" ] ; then
                    echo "$firstname$lastname"
                else
                    if [ $firstname != "" ] ; then
                        echo "$firstname,"
                    elif [ $lastname != "" ] ; then
                        echo "$lastname"
                    else
                        echo "$num"
                    fi
                fi

            done < "contactlist.txt" )
idlist=$(while read line
            do
                idnum=$(echo $line | awk 'BEGIN { FS="|" } { print $1}')
                echo $idnum
            done < "contactlist.txt" )

sortcontact=$(printf "%s\n" $contact | sort)

selected=$(yad --title="Contacts" --width=200 --height=200 --button="DISPLAY:2" --button="ADD:3" --list --separator=""  --column="List" $sortcontact --column="ID:NUM" $idlist)

输出:$ idlist和$ sortcontact都混淆了。

我想要的是:列ID应该只有$ idlist,而列List应该只有$ sortcontact。

txt文件:

1|Joanne|Perez|9173046751.000000|Mar 31|
2|Nikko|Real|9065887272.000000|Mar 21|
3|Try|Haha|9000000000.000000|Jan 15|
4|Nikko|Real|9065887272.000000|Jan 21|
5|Paolo|Perez|9212345678.000000|Jan 25|

1 个答案:

答案 0 :(得分:1)

#!/usr/bin/env bash
items=()
while IFS='|' read -r idnum firstname lastname num birthday _; do
    if [[ $firstname || $lastname ]]; then
        items+=( "$firstname $lastname" "$idnum" )
    else
        items+=( "$num" "$idnum" )
    fi
done < <(sort -t'|' -k2 contactlist.txt)

selected=$(yad --title=Contacts --width=200 --height=200 \
               --button=DISPLAY:2 --button=ADD:3 --list \
               --separator= --column=List --column=ID:NUM \
               "${items[@]}")

geirha回答:https://askubuntu.com/questions/408710/yad-list-columns/408732?noredirect=1#408732