Can someone tell me how to calculate the line number of a selected item. I would like to have the specific line number to refer to a subroutine that will process the same line of a different file.
#! /bin/bash
item=$(zenity --list "Apples" "Peaches" "Pumpkin" "Pie" \
--column="Select your choice" --text="Text above column(s)" --title="My menu")
linenumber=x # Formula to calculate the line number of the selected item here
echo "You selected: $item which is in line number: $linenumber"
The desired output is:
You selected Peaches which is in line number: 2
Update:
This is an example of the items that are read. I used the fruit in the script above to illustrate a line example. This is an example of the specific items. As you can see some of the actual text is duplicated but on a different line. When the user select an item, I'm hoping that Zenity has an option to show which line was clicked. Every time it's run it will have a different list of items.
cairo-dock
Desktop
XdndCollectionWindowImp
unity-launcher
unity-panel
unity-panel
unity-dash
Hud
Your turn - Play esskwa003 in HneO9CtF • lichess.org - Google Chrome
ljames@ubunzeus
ljames@ubuntuserver
ljames@hera5
site
site
ljames@ubunzeus
launcher - Add Unity Entry for Locally Installed Program - Ask Ubuntu - Google Chrome
ljames@ubunzeus
eclipse desktop launcher categories - Google Search - Google Chrome
launcher - Add Unity Entry for Locally Installed Program - Ask Ubuntu - Google Chrome
eclipse
MightyText - Google Chrome
launcher - Add Unity Entry for Locally Installed Program - Ask Ubuntu - Google Chrome
ljames@ubunzeus
Inbox - L. D. James - Mozilla Thunderbird
ljames@hera5
ljames@hera5
ljames@ubunzeus
ljames@hera5
How to get the line number of a Zenity selected Item - Unix & Linux Stack Exchange - Google Chrome
workspace - MyPyDev - ShellTools/SEWork/SEWork/hkrecord.sh - Eclipse - /home/users/l/j/ljames/workspace
email - Mozilla Thunderbird
command line - Is it possible to control the recording if Audacity is running in the background? - Ask Ubuntu - Google Chrome
Bookmark Manager - Google Chrome
Formatting Sandbox - Meta Stack Exchange - Google Chrome
Apollo III Support - Backing up the Office Computer - Mozilla Thunderbird
This is the exact block that I have for calling the above data:
#!/bin/bash
INPUT=$HOME/infile.txt
# IFS=$'\n'
item=$(while read l
do
echo "$l"
done <$INPUT|zenity --list --text "sample text " --column "Choose")
echo "You selected: [$item] which is in line number: [$linenumber"]