#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Delete all files if another files in the same directory has a matching occurence of a


    Hello,
    I have several files in a specific directory.
    A specific string in one file can occur in another files.
    If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string.

    Example.
    file1
    ShortName "Blue Jeans"
    price 89.47
    cur EURO
    file2
    ShortName "Blue Jeans"
    Price 59.47
    CUR USD
    file3
    ShortName "Blue Jeans"
    Price 99.47
    CUR GBP
    Since the value of ShortName "Blue Jeans" is occuring in file2 & file3. Both this file should be deleted. Similarly files with other ShortName
    Could any one please help me how can it done via script (ksh, SED, AWK). I am on solaris.

    Thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,200
    Rep Power
    14
    ShortName "Blue Jeans"

    is not a really good way....
    grep -c "ShortName .Blue Jeans"
    give you the NUMBER of files containing this string
    if less 2, exit
    grep -l "ShortName .Blue Jeans"
    give a LIST of files containing this string
    skip the first and kill the rest
    regards
    working on Solaris[5-9], preferred languages french and C.

IMN logo majestic logo threadwatch logo seochat tools logo