sed + delete all words that not contain string before the “dot string”How to detect the user has logged...

Boss wants me to ignore a software API license prohibiting mass download

My cat is a houdini

Can I string ethernet cables?

If you know the location of an invisible creature, can you attack it?

Why is Python 2.7 still the default Python version in Ubuntu?

How to Check all AD userers for "blank" password?

Do Reform Jews believe in a theistic God?

Why is the result of ('b'+'a'+ + 'a' + 'a').toLowerCase() 'banana'?

Who invented Monoid?

Why is there a large performance impact when looping over an array over 240 elements?

How can I see if the data in a SQL Server table is page-compressed?

How big are the Choedan Kal?

How to "add" units to results of pgfmathsetmacro?

Are there really no countries that protect Freedom of Speech as the United States does?

Why command hierarchy, if the chain of command is standing next to each other?

Modeling the uncertainty of the input parameters

Are employers legally allowed to pay employees in goods and services equal to or greater than the minimum wage?

Why is the second S silent in "Sens dessus dessous"?

Can lodestones be used to magnetize crude iron weapons?

What is a good class if we remove subclasses?

How to remove ambiguity: "... lives in the city of H, the capital of the province of NS, WHERE the unemployment rate is ..."?

What is the difference between 王 and 皇?

Why aren’t there water shutoff valves for each room?

Running code generated in realtime in JavaScript with eval()



sed + delete all words that not contain string before the “dot string”


How to detect the user has logged in a domain or local host in the linux shell script?Delete all lines that contain duplicate lettersSed substitute with 3 lines sliding windowsvalidate file content with bash Regular Expressionsfind xml file that contain specific tag name and print the words between tag nameWhat is the best approach to find a system's domain name?find + print the files with time stampHow can i remove duplicate files that contain 2 matching strings but keep the rest?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I castrated the following sed syntax in order to remove from file any host
that not contain linux/LINUX



 sed -i '/linux|LINUX/!d' file


example



linux01.moon.com
solaris.moon.com
UNIX.foot.com


it will give



linux01.moon.com


but now we have other scenario that domains also include linux name as



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


it will give



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


instead of



    linux01.room_linux.com
linux02.gt.com
linux03.klist.com


so how to change my sed syntax in order to ignore the domain name if include linux or LINUX ?










share|improve this question



























  • Are you sure you don't want to select hosts with linux in the name as soon as they also have linux in the domain? Sure?

    – Philippos
    16 hours ago











  • I want to ignore what is in the domain , so if domain include any linux/LINUX then it will not remove it

    – yael
    16 hours ago











  • But then why don't you want linux01.room_linux.com? It has linux in the host name.

    – Philippos
    16 hours ago











  • sorry I agree - you right

    – yael
    16 hours ago











  • see my update , again I am very sorry about this - you right

    – yael
    16 hours ago


















1















I castrated the following sed syntax in order to remove from file any host
that not contain linux/LINUX



 sed -i '/linux|LINUX/!d' file


example



linux01.moon.com
solaris.moon.com
UNIX.foot.com


it will give



linux01.moon.com


but now we have other scenario that domains also include linux name as



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


it will give



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


instead of



    linux01.room_linux.com
linux02.gt.com
linux03.klist.com


so how to change my sed syntax in order to ignore the domain name if include linux or LINUX ?










share|improve this question



























  • Are you sure you don't want to select hosts with linux in the name as soon as they also have linux in the domain? Sure?

    – Philippos
    16 hours ago











  • I want to ignore what is in the domain , so if domain include any linux/LINUX then it will not remove it

    – yael
    16 hours ago











  • But then why don't you want linux01.room_linux.com? It has linux in the host name.

    – Philippos
    16 hours ago











  • sorry I agree - you right

    – yael
    16 hours ago











  • see my update , again I am very sorry about this - you right

    – yael
    16 hours ago














1












1








1








I castrated the following sed syntax in order to remove from file any host
that not contain linux/LINUX



 sed -i '/linux|LINUX/!d' file


example



linux01.moon.com
solaris.moon.com
UNIX.foot.com


it will give



linux01.moon.com


but now we have other scenario that domains also include linux name as



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


it will give



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


instead of



    linux01.room_linux.com
linux02.gt.com
linux03.klist.com


so how to change my sed syntax in order to ignore the domain name if include linux or LINUX ?










share|improve this question
















I castrated the following sed syntax in order to remove from file any host
that not contain linux/LINUX



 sed -i '/linux|LINUX/!d' file


example



linux01.moon.com
solaris.moon.com
UNIX.foot.com


it will give



linux01.moon.com


but now we have other scenario that domains also include linux name as



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


it will give



linux01.room_linux.com
linux02.gt.com
linux03.klist.com
sol.linux.com


instead of



    linux01.room_linux.com
linux02.gt.com
linux03.klist.com


so how to change my sed syntax in order to ignore the domain name if include linux or LINUX ?







linux sed regular-expression






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 hours ago









Jeff Schaller

48.8k11 gold badges72 silver badges162 bronze badges




48.8k11 gold badges72 silver badges162 bronze badges










asked 16 hours ago









yaelyael

2,9818 gold badges42 silver badges92 bronze badges




2,9818 gold badges42 silver badges92 bronze badges
















  • Are you sure you don't want to select hosts with linux in the name as soon as they also have linux in the domain? Sure?

    – Philippos
    16 hours ago











  • I want to ignore what is in the domain , so if domain include any linux/LINUX then it will not remove it

    – yael
    16 hours ago











  • But then why don't you want linux01.room_linux.com? It has linux in the host name.

    – Philippos
    16 hours ago











  • sorry I agree - you right

    – yael
    16 hours ago











  • see my update , again I am very sorry about this - you right

    – yael
    16 hours ago



















  • Are you sure you don't want to select hosts with linux in the name as soon as they also have linux in the domain? Sure?

    – Philippos
    16 hours ago











  • I want to ignore what is in the domain , so if domain include any linux/LINUX then it will not remove it

    – yael
    16 hours ago











  • But then why don't you want linux01.room_linux.com? It has linux in the host name.

    – Philippos
    16 hours ago











  • sorry I agree - you right

    – yael
    16 hours ago











  • see my update , again I am very sorry about this - you right

    – yael
    16 hours ago

















Are you sure you don't want to select hosts with linux in the name as soon as they also have linux in the domain? Sure?

– Philippos
16 hours ago





Are you sure you don't want to select hosts with linux in the name as soon as they also have linux in the domain? Sure?

– Philippos
16 hours ago













I want to ignore what is in the domain , so if domain include any linux/LINUX then it will not remove it

– yael
16 hours ago





I want to ignore what is in the domain , so if domain include any linux/LINUX then it will not remove it

– yael
16 hours ago













But then why don't you want linux01.room_linux.com? It has linux in the host name.

– Philippos
16 hours ago





But then why don't you want linux01.room_linux.com? It has linux in the host name.

– Philippos
16 hours ago













sorry I agree - you right

– yael
16 hours ago





sorry I agree - you right

– yael
16 hours ago













see my update , again I am very sorry about this - you right

– yael
16 hours ago





see my update , again I am very sorry about this - you right

– yael
16 hours ago










2 Answers
2






active

oldest

votes


















1














You need to fix the pattern to the start of the line with ^ and then allow only other characters than the dot ([^.]*) until your keyword is found:



sed -E '/^[^.]*(linux|LINUX)/!d'


Note that you need to add braces around your alternative patterns. I switched to extended regular expressions to make it more readable.






share|improve this answer


























  • the problem is that - its removed all hosts in the file , so we get file empty

    – yael
    16 hours ago











  • we have redhat 7.2 OS , on which OS you try it?

    – yael
    16 hours ago











  • This can't be an OS version issue. If your sed accepts option -E it will work. Or do your lines contain other stuff before the host?

    – Philippos
    16 hours ago











  • I means I use the syntax - sed -iE '/^[^.]*(linux|LINUX)/!d' ( why -i flag cause remove of all hosts ? )

    – yael
    16 hours ago













  • Never concatenate options after -i! This will make the E an argument (backup file extension) for the -i option and lose the -E option! Use -i -E or -Ei.

    – Philippos
    16 hours ago



















0














$ sed -e '
h
s/..*//;y/linux/LINUX/;/LINUX/!d
g
' inp.file


This is the Posix sed approach you could take.






share|improve this answer




























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535352%2fsed-delete-all-words-that-not-contain-string-before-the-dot-string%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You need to fix the pattern to the start of the line with ^ and then allow only other characters than the dot ([^.]*) until your keyword is found:



    sed -E '/^[^.]*(linux|LINUX)/!d'


    Note that you need to add braces around your alternative patterns. I switched to extended regular expressions to make it more readable.






    share|improve this answer


























    • the problem is that - its removed all hosts in the file , so we get file empty

      – yael
      16 hours ago











    • we have redhat 7.2 OS , on which OS you try it?

      – yael
      16 hours ago











    • This can't be an OS version issue. If your sed accepts option -E it will work. Or do your lines contain other stuff before the host?

      – Philippos
      16 hours ago











    • I means I use the syntax - sed -iE '/^[^.]*(linux|LINUX)/!d' ( why -i flag cause remove of all hosts ? )

      – yael
      16 hours ago













    • Never concatenate options after -i! This will make the E an argument (backup file extension) for the -i option and lose the -E option! Use -i -E or -Ei.

      – Philippos
      16 hours ago
















    1














    You need to fix the pattern to the start of the line with ^ and then allow only other characters than the dot ([^.]*) until your keyword is found:



    sed -E '/^[^.]*(linux|LINUX)/!d'


    Note that you need to add braces around your alternative patterns. I switched to extended regular expressions to make it more readable.






    share|improve this answer


























    • the problem is that - its removed all hosts in the file , so we get file empty

      – yael
      16 hours ago











    • we have redhat 7.2 OS , on which OS you try it?

      – yael
      16 hours ago











    • This can't be an OS version issue. If your sed accepts option -E it will work. Or do your lines contain other stuff before the host?

      – Philippos
      16 hours ago











    • I means I use the syntax - sed -iE '/^[^.]*(linux|LINUX)/!d' ( why -i flag cause remove of all hosts ? )

      – yael
      16 hours ago













    • Never concatenate options after -i! This will make the E an argument (backup file extension) for the -i option and lose the -E option! Use -i -E or -Ei.

      – Philippos
      16 hours ago














    1












    1








    1







    You need to fix the pattern to the start of the line with ^ and then allow only other characters than the dot ([^.]*) until your keyword is found:



    sed -E '/^[^.]*(linux|LINUX)/!d'


    Note that you need to add braces around your alternative patterns. I switched to extended regular expressions to make it more readable.






    share|improve this answer













    You need to fix the pattern to the start of the line with ^ and then allow only other characters than the dot ([^.]*) until your keyword is found:



    sed -E '/^[^.]*(linux|LINUX)/!d'


    Note that you need to add braces around your alternative patterns. I switched to extended regular expressions to make it more readable.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 16 hours ago









    PhilipposPhilippos

    7,1391 gold badge20 silver badges52 bronze badges




    7,1391 gold badge20 silver badges52 bronze badges
















    • the problem is that - its removed all hosts in the file , so we get file empty

      – yael
      16 hours ago











    • we have redhat 7.2 OS , on which OS you try it?

      – yael
      16 hours ago











    • This can't be an OS version issue. If your sed accepts option -E it will work. Or do your lines contain other stuff before the host?

      – Philippos
      16 hours ago











    • I means I use the syntax - sed -iE '/^[^.]*(linux|LINUX)/!d' ( why -i flag cause remove of all hosts ? )

      – yael
      16 hours ago













    • Never concatenate options after -i! This will make the E an argument (backup file extension) for the -i option and lose the -E option! Use -i -E or -Ei.

      – Philippos
      16 hours ago



















    • the problem is that - its removed all hosts in the file , so we get file empty

      – yael
      16 hours ago











    • we have redhat 7.2 OS , on which OS you try it?

      – yael
      16 hours ago











    • This can't be an OS version issue. If your sed accepts option -E it will work. Or do your lines contain other stuff before the host?

      – Philippos
      16 hours ago











    • I means I use the syntax - sed -iE '/^[^.]*(linux|LINUX)/!d' ( why -i flag cause remove of all hosts ? )

      – yael
      16 hours ago













    • Never concatenate options after -i! This will make the E an argument (backup file extension) for the -i option and lose the -E option! Use -i -E or -Ei.

      – Philippos
      16 hours ago

















    the problem is that - its removed all hosts in the file , so we get file empty

    – yael
    16 hours ago





    the problem is that - its removed all hosts in the file , so we get file empty

    – yael
    16 hours ago













    we have redhat 7.2 OS , on which OS you try it?

    – yael
    16 hours ago





    we have redhat 7.2 OS , on which OS you try it?

    – yael
    16 hours ago













    This can't be an OS version issue. If your sed accepts option -E it will work. Or do your lines contain other stuff before the host?

    – Philippos
    16 hours ago





    This can't be an OS version issue. If your sed accepts option -E it will work. Or do your lines contain other stuff before the host?

    – Philippos
    16 hours ago













    I means I use the syntax - sed -iE '/^[^.]*(linux|LINUX)/!d' ( why -i flag cause remove of all hosts ? )

    – yael
    16 hours ago







    I means I use the syntax - sed -iE '/^[^.]*(linux|LINUX)/!d' ( why -i flag cause remove of all hosts ? )

    – yael
    16 hours ago















    Never concatenate options after -i! This will make the E an argument (backup file extension) for the -i option and lose the -E option! Use -i -E or -Ei.

    – Philippos
    16 hours ago





    Never concatenate options after -i! This will make the E an argument (backup file extension) for the -i option and lose the -E option! Use -i -E or -Ei.

    – Philippos
    16 hours ago













    0














    $ sed -e '
    h
    s/..*//;y/linux/LINUX/;/LINUX/!d
    g
    ' inp.file


    This is the Posix sed approach you could take.






    share|improve this answer






























      0














      $ sed -e '
      h
      s/..*//;y/linux/LINUX/;/LINUX/!d
      g
      ' inp.file


      This is the Posix sed approach you could take.






      share|improve this answer




























        0












        0








        0







        $ sed -e '
        h
        s/..*//;y/linux/LINUX/;/LINUX/!d
        g
        ' inp.file


        This is the Posix sed approach you could take.






        share|improve this answer













        $ sed -e '
        h
        s/..*//;y/linux/LINUX/;/LINUX/!d
        g
        ' inp.file


        This is the Posix sed approach you could take.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 53 mins ago









        Rakesh SharmaRakesh Sharma

        1011 silver badge2 bronze badges




        1011 silver badge2 bronze badges

































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535352%2fsed-delete-all-words-that-not-contain-string-before-the-dot-string%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...