Announcement

Collapse
No announcement yet.

Zenity List Command

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Zenity List Command

    Hello people. I am trying to get a Zenity command to do something, I am almost certain this is possible. I want it to read in the list from a csv file.

    Code:
    #!/bin/bash
    # Replace CRLF with commas
    file=$(cat test.csv| tr , '\n')
    # Fill Array
    item=($file)
    zenity --list --title="Zenity List" --width=640 --height=480 --column="Name" --column="Phone" --column="Address" "${item[@]}"
    When I tried separator="," or separator=, it still separates the fields on space. What am I not seeing here?

    #2
    Can you give an example of input and output desired? Might be another way to skin the cat, like setting IFS instead of stripping CRLF

    Please Read Me

    Comment


      #3
      Or maybe just separator=', '

      Please Read Me

      Comment


        #4
        Most CSV file formats are commonly separated with commas;

        Code:
        Simon Tomoko,1234578,909 My Street
        Jane Doe,private,behind the Chinese Steakhouse 
        Michael A. John,999,April Street
        At the end they use the CRLF to separate the rows. Zenity hard coded would be this;
        Code:
        #!/bin/bash
        zenity --list --title="Zenity List" --width=640 --height=480 --column="Name" --column="Phone" --column="Address"  "Simon Tomoko" "1234578" "909 My Street" "Jane Doe" "private" "behind the Chinese Steakhouse" "Michael A. John" "999" "April Street"
        --update--
        Upon further study my line to replace the end of line is somewhat botched. Also I guess I should be converting the file string variable from this:

        Code:
        Simon Tomoko,1234578,909 My Street
        Jane Doe,private,behind the Chinese Steakhouse 
        Michael A. John,999,April Street
        to this:

        Code:
        "Simon Tomoko" "1234578" "909 My Street" "Jane Doe" "private" "behind the Chinese Steakhouse" "Michael A. John" "999" "April Street"
        I have done some searching and still I am not finding method.
        I can do the reverse very easy:
        Code:
        zenity --forms --title "Zenity Form" --separator="," --add-entry=Name --add-entry="User ID" --add-password=Password >> password.csv
        Last edited by Simon; May 21, 2014, 05:59 PM.

        Comment


          #5
          The problems is not in Zenity, it is in the creating of the array:
          Code:
          # save old IFS
          oldifs=$IFS
          # fields defined by comma and newline
          IFS=',
          '
          item=($(cat file.csv))
          # restore IFS
          IFS=$oldifs
          echo ${item[0]}
          this should show the correct first field.

          Comment


            #6
            Thanks! This is the the way I implemented it;

            Code:
            #!/bin/bash
            #
            oldifs=$IFS
            IFS=','
            item=($(cat file.csv|tr '\n' ','))
            IFS=$oldifs
            zenity --list --title="Zenity List" --width=640 --height=480 --column="Name" --column="Phone" --column="Adress"  "${item[@]}"

            Comment

            Working...
            X