DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Unix Query

  1. #1
    Join Date
    May 2001
    Location
    London
    Posts
    149
    I have file 203.195.159.11_2-day.png , i want to store 203.195.159.11_2-day only in my variable

    My shells script :

    a=0
    for filename in *.png
    do
    a=filename---------------------Here I have to make some changes
    convert $filename $filename".gif"
    done

    I want to store in variable a=203.195.159.11_2-day

    Thanks


    Paresh

  2. #2
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    for filename in `ls *.png`
    do
    a=`echo $filename | cut -d. -f1`
    echo $a
    done

  3. #3
    Join Date
    May 2001
    Location
    London
    Posts
    149
    for filename in `ls *.png`
    do
    a=`echo $filename | cut -d. -f1`
    echo $a
    done

    I have aroung 30 .png files in the directory.
    actually filename is 203.195.159.11_2-day.png
    and I want to store 203.195.159.11_2-day
    but your 3 rd statement actually stores 203 only.

    Paresh

  4. #4
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    oh sorry, hadn't noticed all the dots in the filename
    just use -f1-4 instead of -f1
    BTW : this will only work if all your filenames are made of IP addresses, since it cuts using dot '.' as a field separator, and it takes the first 4 fields ... else you can do :
    echo $^filename | sed 's/\.png$//'

  5. #5
    Join Date
    May 2001
    Location
    London
    Posts
    149
    Thanks PIPO

    It worked

    Paresh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width