1

我需要一些关于 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|
4

1 回答 1

2
#!/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

于 2014-01-21T14:21:27.820 回答