Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Smile Help with excluding datasets.


    Hi All

    I am trying to sort data while running a command against an input file.

    This is what my command looks like:

    input file "idlist.txt" contains the following: (Note some duplicates)
    /path/path/path/path/id1
    /path/path/path/path/id2
    /path/path/path/path/id3
    /path/path/path/path/id1
    /path/path/path/path/id4
    /path/path/path/path/id5
    /path/path/path/path/id2

    command I am running against this is:
    for i in `cat idlist.txt | awk -F "/" {'print $NF'} | sort -u`; do custom_app_command -q id=$i -r model,make,location ; done

    (fictitious - custom_app_command -q id=$i -r model,make,location - cannot post due to confidentiality)

    My output is this then:

    model make location
    Mondeo Ford South Africa
    Ranger Ford Alaska
    F250 Ford Canada

    model make location
    Ranger Ford Alaska

    model make location
    Ranger Ford Alaska
    F250 Ford Canada

    model make location
    Mondeo Ford South Africa

    model make location
    Mondeo Ford South Africa
    Ranger Ford Alaska
    F250 Ford Canada

    My ask is this, I would like to exclude any of the sets that contains the words "South Africa" meaning that I would only have the following output remaining:


    model make location
    Ranger Ford Alaska
    F250 Ford Canada

    model make location
    Ranger Ford Alaska

    Also if I would like to exclude more than one word e.g. "South Africa" and "Canada" then I would have only the following remaining:

    model make location
    Ranger Ford Alaska

    I am asking for excluding, since the list I am working with is huge and excluding would be easier than including.

    Any advice would be appreciated

  2. #2
    Hi,

    first, don't use a for loop to read a file :
    Code:
    while IFS='/' read -a ar; do echo "${ar[@]: -1}"; done < idlist.txt
    next, grep -v and the appropriate regex should do the job.

  3. #3
    -->
    if "South Africa" word in first data file
    Code:
    for i in `cat idlist.txt | awk -F "/" '{a=$NF; if (a != "South Africa") print a}' | sort -u`
    {
    custom_app_command -q id=$i -r model,make,location
    }
    if "South Africa" word resulted by your command
    Code:
    for i in `cat idlist.txt | awk -F "/" '{a=$NF; print a}' | sort -u`
    {
    custom_app_command -q id=$i -r model,make,location
    } | grep -vPe 'South Africa'
    Last edited by abdan; 03-29-2018 at 12:11 PM.

$spacer_open
$spacer_close

Posting Permissions

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