Extract lines from files with names begining with given lettersed - change lines that start with one given word and end with another?Delete lines from a file using awk or sed based on the variable from previous commandFill empty lines in specific column with valuesextract servers' blocks from Nginx confExclude lines that have less than 23 columnsHow to replace rows that nth to mth columns from them are empty using sed or awk based with run commandPrint if for the same 1st field there's a single value of 2nd field on all linesReplace range of lines with range of lines (sed or others)How to convert columns into row where each column has multiple values?Generate Text File With Only 7th and 8th Columns From Given ls Command Output

How do I experimentally measure the surface area of a rock?

Where do I put nobles/royalty in a scifi military

Thinking about the notes when playing a piece

Seven Pounds Eight and Eight Pence

Receive a list of names and return a list of users - HackerRank test

Interview question: If correlation doesn't imply causation, how do you detect causation?

Where and/or why is a slanted hyphen used?

What is the purpose of R1 in this circuit?

What's the difference between a creature "can't move" and a creature's "speed becomes 0 and it can't benefit from any bonus to its speed."?

Origin of the Latin Language?

Does the German President's apology for WWII reflect the views of the people of Germany?

The quietest classical orchestra instrument to play at home

"Readability is one thing, legibility is another", translation into french

Does a lich die if its phylactery is destroyed, or can it simply not rejuvenate anymore?

Doing chemistry under water?

What's the difference between words "tongue" and "lingua"?

How can I prevent renaming the arguments to Function[...,...] for making plots of spherical harmonics coloured by phase

Why is the Exchange French considered drawish?

Does every truth have to be provable based on evidence?

What makes an airport "international"?

Affrication-like sound in palatal plosive [c]

Expand a recursive pattern

How to test oom-killer from command line

White marks on garage ceiling



Extract lines from files with names begining with given letter


sed - change lines that start with one given word and end with another?Delete lines from a file using awk or sed based on the variable from previous commandFill empty lines in specific column with valuesextract servers' blocks from Nginx confExclude lines that have less than 23 columnsHow to replace rows that nth to mth columns from them are empty using sed or awk based with run commandPrint if for the same 1st field there's a single value of 2nd field on all linesReplace range of lines with range of lines (sed or others)How to convert columns into row where each column has multiple values?Generate Text File With Only 7th and 8th Columns From Given ls Command Output






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









8

















Got here a list of columns, as follows:



59 LOUIS 1202 +1
60 FREDDIE 1201 +4
61 FINLAY 1200 -2
62 LEON 1137 +12
63 HARLEY 1132 +6
64 DAVID 1127 -1
65 MOHAMMAD1100 +6
66 REECE 1095 -1
67 KIAN 1090 0
68 KAI 1056 -6
69 KYLE 1030 -18
70 BRANDON 1011 -4
71 HAYDEN 1006 +5
72 ZACHARY 995 +10
73 KIERAN 973 -12
73 LUCA 973 -1
75 ASHTON 954 +4
76 BAILEY 939 -6
77 JAKE 913 +10
78 GABRIEL 910 +14
79 SAM 900 -2
80 EVAN 890 0
81 BRADLEY 847 -13


How could be extracted only the lines with, for example, letter "L", as follows:



73 LUCA 973 -1









share|improve this question























  • 3





    Does the L need to be in the second column? How are columns defined (spaces? tabs?)? Can the L be anywhere in the column or does it have to be the first letter? Your question says only "with", but you seem to be expecting "starts with". Please edit your question and clarify.

    – terdon
    Oct 15 at 18:23











  • Its to extract the lines which contains the name with given letter, for example: Need here lines which names starts with letter "E", then it should return a file that contains 80 EVAN 890 0 only, just as the guy down there just answered.

    – Rubem74
    Oct 15 at 18:46











  • Just curious about the [sed] tag: does the solution have to use sed?

    – Christopher Schultz
    Oct 18 at 19:00

















8

















Got here a list of columns, as follows:



59 LOUIS 1202 +1
60 FREDDIE 1201 +4
61 FINLAY 1200 -2
62 LEON 1137 +12
63 HARLEY 1132 +6
64 DAVID 1127 -1
65 MOHAMMAD1100 +6
66 REECE 1095 -1
67 KIAN 1090 0
68 KAI 1056 -6
69 KYLE 1030 -18
70 BRANDON 1011 -4
71 HAYDEN 1006 +5
72 ZACHARY 995 +10
73 KIERAN 973 -12
73 LUCA 973 -1
75 ASHTON 954 +4
76 BAILEY 939 -6
77 JAKE 913 +10
78 GABRIEL 910 +14
79 SAM 900 -2
80 EVAN 890 0
81 BRADLEY 847 -13


How could be extracted only the lines with, for example, letter "L", as follows:



73 LUCA 973 -1









share|improve this question























  • 3





    Does the L need to be in the second column? How are columns defined (spaces? tabs?)? Can the L be anywhere in the column or does it have to be the first letter? Your question says only "with", but you seem to be expecting "starts with". Please edit your question and clarify.

    – terdon
    Oct 15 at 18:23











  • Its to extract the lines which contains the name with given letter, for example: Need here lines which names starts with letter "E", then it should return a file that contains 80 EVAN 890 0 only, just as the guy down there just answered.

    – Rubem74
    Oct 15 at 18:46











  • Just curious about the [sed] tag: does the solution have to use sed?

    – Christopher Schultz
    Oct 18 at 19:00













8












8








8


1






Got here a list of columns, as follows:



59 LOUIS 1202 +1
60 FREDDIE 1201 +4
61 FINLAY 1200 -2
62 LEON 1137 +12
63 HARLEY 1132 +6
64 DAVID 1127 -1
65 MOHAMMAD1100 +6
66 REECE 1095 -1
67 KIAN 1090 0
68 KAI 1056 -6
69 KYLE 1030 -18
70 BRANDON 1011 -4
71 HAYDEN 1006 +5
72 ZACHARY 995 +10
73 KIERAN 973 -12
73 LUCA 973 -1
75 ASHTON 954 +4
76 BAILEY 939 -6
77 JAKE 913 +10
78 GABRIEL 910 +14
79 SAM 900 -2
80 EVAN 890 0
81 BRADLEY 847 -13


How could be extracted only the lines with, for example, letter "L", as follows:



73 LUCA 973 -1









share|improve this question

















Got here a list of columns, as follows:



59 LOUIS 1202 +1
60 FREDDIE 1201 +4
61 FINLAY 1200 -2
62 LEON 1137 +12
63 HARLEY 1132 +6
64 DAVID 1127 -1
65 MOHAMMAD1100 +6
66 REECE 1095 -1
67 KIAN 1090 0
68 KAI 1056 -6
69 KYLE 1030 -18
70 BRANDON 1011 -4
71 HAYDEN 1006 +5
72 ZACHARY 995 +10
73 KIERAN 973 -12
73 LUCA 973 -1
75 ASHTON 954 +4
76 BAILEY 939 -6
77 JAKE 913 +10
78 GABRIEL 910 +14
79 SAM 900 -2
80 EVAN 890 0
81 BRADLEY 847 -13


How could be extracted only the lines with, for example, letter "L", as follows:



73 LUCA 973 -1






text-processing sed regular-expression






share|improve this question
















share|improve this question













share|improve this question




share|improve this question








edited Oct 15 at 18:22









terdon

145k38 gold badges299 silver badges479 bronze badges




145k38 gold badges299 silver badges479 bronze badges










asked Oct 15 at 18:19









Rubem74Rubem74

806 bronze badges




806 bronze badges










  • 3





    Does the L need to be in the second column? How are columns defined (spaces? tabs?)? Can the L be anywhere in the column or does it have to be the first letter? Your question says only "with", but you seem to be expecting "starts with". Please edit your question and clarify.

    – terdon
    Oct 15 at 18:23











  • Its to extract the lines which contains the name with given letter, for example: Need here lines which names starts with letter "E", then it should return a file that contains 80 EVAN 890 0 only, just as the guy down there just answered.

    – Rubem74
    Oct 15 at 18:46











  • Just curious about the [sed] tag: does the solution have to use sed?

    – Christopher Schultz
    Oct 18 at 19:00












  • 3





    Does the L need to be in the second column? How are columns defined (spaces? tabs?)? Can the L be anywhere in the column or does it have to be the first letter? Your question says only "with", but you seem to be expecting "starts with". Please edit your question and clarify.

    – terdon
    Oct 15 at 18:23











  • Its to extract the lines which contains the name with given letter, for example: Need here lines which names starts with letter "E", then it should return a file that contains 80 EVAN 890 0 only, just as the guy down there just answered.

    – Rubem74
    Oct 15 at 18:46











  • Just curious about the [sed] tag: does the solution have to use sed?

    – Christopher Schultz
    Oct 18 at 19:00







3




3





Does the L need to be in the second column? How are columns defined (spaces? tabs?)? Can the L be anywhere in the column or does it have to be the first letter? Your question says only "with", but you seem to be expecting "starts with". Please edit your question and clarify.

– terdon
Oct 15 at 18:23





Does the L need to be in the second column? How are columns defined (spaces? tabs?)? Can the L be anywhere in the column or does it have to be the first letter? Your question says only "with", but you seem to be expecting "starts with". Please edit your question and clarify.

– terdon
Oct 15 at 18:23













Its to extract the lines which contains the name with given letter, for example: Need here lines which names starts with letter "E", then it should return a file that contains 80 EVAN 890 0 only, just as the guy down there just answered.

– Rubem74
Oct 15 at 18:46





Its to extract the lines which contains the name with given letter, for example: Need here lines which names starts with letter "E", then it should return a file that contains 80 EVAN 890 0 only, just as the guy down there just answered.

– Rubem74
Oct 15 at 18:46













Just curious about the [sed] tag: does the solution have to use sed?

– Christopher Schultz
Oct 18 at 19:00





Just curious about the [sed] tag: does the solution have to use sed?

– Christopher Schultz
Oct 18 at 19:00










6 Answers
6






active

oldest

votes


















5


















That seems to be duplicated, but anyway, if it was understood, one may do it as follows:



First, save the list in a some nameslist.txt file, then:



sed -rn '/^[^s]+s+[F]/p' list.txt > result.txt, which should return following output in result.txt file:



60 FREDDIE 1201 +4
61 FINLAY 1200 -2






share|improve this answer

































    19


















    awk '$2 ~ /^L/' file


    Tells awk to test the second field $2 using the regex ~ expression ^L and print the matching lines.



    The regex matches any field (string) that starts ^ with an L






    share|improve this answer


























    • awk 'substr($2, 1, 1) == "L"' file would also work

      – glenn jackman
      Oct 15 at 19:59











    • @glennjackman Are there any benifits to using substr over a regex field match as in this answer?

      – Paul Evans
      Oct 16 at 22:33












    • Don't know. There may be a new microseconds performance benefit, but there may not be. I was just pointing out an alternate function.

      – glenn jackman
      Oct 17 at 0:54


















    7


















    Building on @bu5hman's answer: With awk, you can easily pass the letter as a parameter:



    awk -v letter="L" 'substr($2, 1, 1) == letter' file
    # or with a constructed regex
    awk -v letter="L" '$2 ~ "^" letter' file





    share|improve this answer























    • 3





      +1. The $2 ~ ... version also allows regexp searches like -v letter='[FL]' to match lines where the name begins with either an F or an L.

      – cas
      Oct 16 at 9:12


















    2


















    Assuming that you have that list in list.txt, you can do the following:



     grep -h L list.txt > list_L.txt 


    Explanation: grep L list.txt gives you all the lines containing an uppercase L. The option -h suppresses the output of the file name, but is only necessary if you are searching through multiple files (e.g. grep -h L lis*.txt). Adding > list_L.txt redirects the lines to the specified file.



    If the L must only occur at the beginning of a "word" (on name, in this case), you need to tweak the above command a bit:



     grep -h '<L' list.txt > list_L.txt 


    Adding < matches the beginning of a "word", so <L selects lines containing a word beginning with an uppercase L.






    share|improve this answer

































      2


















      Another grep example:



      grep -E "[0-9]+ +L" file


      + matches one or more occurrence of the previous character, so in this case we match at least one numeric character, and at least one space, followed by a capital L.



      -E is required to interpret the + as a special character instead of a literal '+'



      output:



      59 LOUIS 1202 +1
      62 LEON 1137 +12
      73 LUCA 973 -1





      share|improve this answer



































        1


















        Avoid RegEx when possible. AWK example:



        index($2, "L") == 1





        share|improve this answer




























        • Why do you think it's a bad idea to answer with a working example like awk 'index($2, "L") == 1' file like everybody else does?

          – Freddy
          Oct 17 at 0:30











        • @Freddy I posted my code carefully and purposefully. Your code is a valid shell script, while mine is a valid AWK script. Please stop changing it.

          – user327359
          Oct 17 at 0:45











        • I stopped changing it, I'm just curious. This question is tagged with sed and not everybody knows how to run your script, that's all.

          – Freddy
          Oct 17 at 0:50











        • @Freddy its public information for at least 20 years now... pubs.opengroup.org/onlinepubs/007908799/xcu/awk.html

          – user327359
          Oct 17 at 1:54











        • This is about as useful as answering with just oldfile newfile without bothering to mention cp, when someone asks "how do i copy a file?" and then snarkily pointing out that cp has been public information for decades. Actually, it's worse than that because "avoid regex when possible" is a terrible answer for a simple text processing problem.

          – cas
          Oct 21 at 4:53












        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/4.0/"u003ecc by-sa 4.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%2f546934%2fextract-lines-from-files-with-names-begining-with-given-letter%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown


























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        5


















        That seems to be duplicated, but anyway, if it was understood, one may do it as follows:



        First, save the list in a some nameslist.txt file, then:



        sed -rn '/^[^s]+s+[F]/p' list.txt > result.txt, which should return following output in result.txt file:



        60 FREDDIE 1201 +4
        61 FINLAY 1200 -2






        share|improve this answer






























          5


















          That seems to be duplicated, but anyway, if it was understood, one may do it as follows:



          First, save the list in a some nameslist.txt file, then:



          sed -rn '/^[^s]+s+[F]/p' list.txt > result.txt, which should return following output in result.txt file:



          60 FREDDIE 1201 +4
          61 FINLAY 1200 -2






          share|improve this answer




























            5














            5










            5









            That seems to be duplicated, but anyway, if it was understood, one may do it as follows:



            First, save the list in a some nameslist.txt file, then:



            sed -rn '/^[^s]+s+[F]/p' list.txt > result.txt, which should return following output in result.txt file:



            60 FREDDIE 1201 +4
            61 FINLAY 1200 -2






            share|improve this answer














            That seems to be duplicated, but anyway, if it was understood, one may do it as follows:



            First, save the list in a some nameslist.txt file, then:



            sed -rn '/^[^s]+s+[F]/p' list.txt > result.txt, which should return following output in result.txt file:



            60 FREDDIE 1201 +4
            61 FINLAY 1200 -2







            share|improve this answer













            share|improve this answer




            share|improve this answer










            answered Oct 15 at 18:36









            Renan41Renan41

            665 bronze badges




            665 bronze badges


























                19


















                awk '$2 ~ /^L/' file


                Tells awk to test the second field $2 using the regex ~ expression ^L and print the matching lines.



                The regex matches any field (string) that starts ^ with an L






                share|improve this answer


























                • awk 'substr($2, 1, 1) == "L"' file would also work

                  – glenn jackman
                  Oct 15 at 19:59











                • @glennjackman Are there any benifits to using substr over a regex field match as in this answer?

                  – Paul Evans
                  Oct 16 at 22:33












                • Don't know. There may be a new microseconds performance benefit, but there may not be. I was just pointing out an alternate function.

                  – glenn jackman
                  Oct 17 at 0:54















                19


















                awk '$2 ~ /^L/' file


                Tells awk to test the second field $2 using the regex ~ expression ^L and print the matching lines.



                The regex matches any field (string) that starts ^ with an L






                share|improve this answer


























                • awk 'substr($2, 1, 1) == "L"' file would also work

                  – glenn jackman
                  Oct 15 at 19:59











                • @glennjackman Are there any benifits to using substr over a regex field match as in this answer?

                  – Paul Evans
                  Oct 16 at 22:33












                • Don't know. There may be a new microseconds performance benefit, but there may not be. I was just pointing out an alternate function.

                  – glenn jackman
                  Oct 17 at 0:54













                19














                19










                19









                awk '$2 ~ /^L/' file


                Tells awk to test the second field $2 using the regex ~ expression ^L and print the matching lines.



                The regex matches any field (string) that starts ^ with an L






                share|improve this answer














                awk '$2 ~ /^L/' file


                Tells awk to test the second field $2 using the regex ~ expression ^L and print the matching lines.



                The regex matches any field (string) that starts ^ with an L







                share|improve this answer













                share|improve this answer




                share|improve this answer










                answered Oct 15 at 18:37









                bu5hmanbu5hman

                2,0911 gold badge4 silver badges17 bronze badges




                2,0911 gold badge4 silver badges17 bronze badges















                • awk 'substr($2, 1, 1) == "L"' file would also work

                  – glenn jackman
                  Oct 15 at 19:59











                • @glennjackman Are there any benifits to using substr over a regex field match as in this answer?

                  – Paul Evans
                  Oct 16 at 22:33












                • Don't know. There may be a new microseconds performance benefit, but there may not be. I was just pointing out an alternate function.

                  – glenn jackman
                  Oct 17 at 0:54

















                • awk 'substr($2, 1, 1) == "L"' file would also work

                  – glenn jackman
                  Oct 15 at 19:59











                • @glennjackman Are there any benifits to using substr over a regex field match as in this answer?

                  – Paul Evans
                  Oct 16 at 22:33












                • Don't know. There may be a new microseconds performance benefit, but there may not be. I was just pointing out an alternate function.

                  – glenn jackman
                  Oct 17 at 0:54
















                awk 'substr($2, 1, 1) == "L"' file would also work

                – glenn jackman
                Oct 15 at 19:59





                awk 'substr($2, 1, 1) == "L"' file would also work

                – glenn jackman
                Oct 15 at 19:59













                @glennjackman Are there any benifits to using substr over a regex field match as in this answer?

                – Paul Evans
                Oct 16 at 22:33






                @glennjackman Are there any benifits to using substr over a regex field match as in this answer?

                – Paul Evans
                Oct 16 at 22:33














                Don't know. There may be a new microseconds performance benefit, but there may not be. I was just pointing out an alternate function.

                – glenn jackman
                Oct 17 at 0:54





                Don't know. There may be a new microseconds performance benefit, but there may not be. I was just pointing out an alternate function.

                – glenn jackman
                Oct 17 at 0:54











                7


















                Building on @bu5hman's answer: With awk, you can easily pass the letter as a parameter:



                awk -v letter="L" 'substr($2, 1, 1) == letter' file
                # or with a constructed regex
                awk -v letter="L" '$2 ~ "^" letter' file





                share|improve this answer























                • 3





                  +1. The $2 ~ ... version also allows regexp searches like -v letter='[FL]' to match lines where the name begins with either an F or an L.

                  – cas
                  Oct 16 at 9:12















                7


















                Building on @bu5hman's answer: With awk, you can easily pass the letter as a parameter:



                awk -v letter="L" 'substr($2, 1, 1) == letter' file
                # or with a constructed regex
                awk -v letter="L" '$2 ~ "^" letter' file





                share|improve this answer























                • 3





                  +1. The $2 ~ ... version also allows regexp searches like -v letter='[FL]' to match lines where the name begins with either an F or an L.

                  – cas
                  Oct 16 at 9:12













                7














                7










                7









                Building on @bu5hman's answer: With awk, you can easily pass the letter as a parameter:



                awk -v letter="L" 'substr($2, 1, 1) == letter' file
                # or with a constructed regex
                awk -v letter="L" '$2 ~ "^" letter' file





                share|improve this answer
















                Building on @bu5hman's answer: With awk, you can easily pass the letter as a parameter:



                awk -v letter="L" 'substr($2, 1, 1) == letter' file
                # or with a constructed regex
                awk -v letter="L" '$2 ~ "^" letter' file






                share|improve this answer















                share|improve this answer




                share|improve this answer








                answered Oct 15 at 20:01


























                community wiki





                glenn jackman











                • 3





                  +1. The $2 ~ ... version also allows regexp searches like -v letter='[FL]' to match lines where the name begins with either an F or an L.

                  – cas
                  Oct 16 at 9:12












                • 3





                  +1. The $2 ~ ... version also allows regexp searches like -v letter='[FL]' to match lines where the name begins with either an F or an L.

                  – cas
                  Oct 16 at 9:12







                3




                3





                +1. The $2 ~ ... version also allows regexp searches like -v letter='[FL]' to match lines where the name begins with either an F or an L.

                – cas
                Oct 16 at 9:12





                +1. The $2 ~ ... version also allows regexp searches like -v letter='[FL]' to match lines where the name begins with either an F or an L.

                – cas
                Oct 16 at 9:12











                2


















                Assuming that you have that list in list.txt, you can do the following:



                 grep -h L list.txt > list_L.txt 


                Explanation: grep L list.txt gives you all the lines containing an uppercase L. The option -h suppresses the output of the file name, but is only necessary if you are searching through multiple files (e.g. grep -h L lis*.txt). Adding > list_L.txt redirects the lines to the specified file.



                If the L must only occur at the beginning of a "word" (on name, in this case), you need to tweak the above command a bit:



                 grep -h '<L' list.txt > list_L.txt 


                Adding < matches the beginning of a "word", so <L selects lines containing a word beginning with an uppercase L.






                share|improve this answer






























                  2


















                  Assuming that you have that list in list.txt, you can do the following:



                   grep -h L list.txt > list_L.txt 


                  Explanation: grep L list.txt gives you all the lines containing an uppercase L. The option -h suppresses the output of the file name, but is only necessary if you are searching through multiple files (e.g. grep -h L lis*.txt). Adding > list_L.txt redirects the lines to the specified file.



                  If the L must only occur at the beginning of a "word" (on name, in this case), you need to tweak the above command a bit:



                   grep -h '<L' list.txt > list_L.txt 


                  Adding < matches the beginning of a "word", so <L selects lines containing a word beginning with an uppercase L.






                  share|improve this answer




























                    2














                    2










                    2









                    Assuming that you have that list in list.txt, you can do the following:



                     grep -h L list.txt > list_L.txt 


                    Explanation: grep L list.txt gives you all the lines containing an uppercase L. The option -h suppresses the output of the file name, but is only necessary if you are searching through multiple files (e.g. grep -h L lis*.txt). Adding > list_L.txt redirects the lines to the specified file.



                    If the L must only occur at the beginning of a "word" (on name, in this case), you need to tweak the above command a bit:



                     grep -h '<L' list.txt > list_L.txt 


                    Adding < matches the beginning of a "word", so <L selects lines containing a word beginning with an uppercase L.






                    share|improve this answer














                    Assuming that you have that list in list.txt, you can do the following:



                     grep -h L list.txt > list_L.txt 


                    Explanation: grep L list.txt gives you all the lines containing an uppercase L. The option -h suppresses the output of the file name, but is only necessary if you are searching through multiple files (e.g. grep -h L lis*.txt). Adding > list_L.txt redirects the lines to the specified file.



                    If the L must only occur at the beginning of a "word" (on name, in this case), you need to tweak the above command a bit:



                     grep -h '<L' list.txt > list_L.txt 


                    Adding < matches the beginning of a "word", so <L selects lines containing a word beginning with an uppercase L.







                    share|improve this answer













                    share|improve this answer




                    share|improve this answer










                    answered Oct 16 at 18:20









                    user800user800

                    3811 gold badge3 silver badges14 bronze badges




                    3811 gold badge3 silver badges14 bronze badges
























                        2


















                        Another grep example:



                        grep -E "[0-9]+ +L" file


                        + matches one or more occurrence of the previous character, so in this case we match at least one numeric character, and at least one space, followed by a capital L.



                        -E is required to interpret the + as a special character instead of a literal '+'



                        output:



                        59 LOUIS 1202 +1
                        62 LEON 1137 +12
                        73 LUCA 973 -1





                        share|improve this answer
































                          2


















                          Another grep example:



                          grep -E "[0-9]+ +L" file


                          + matches one or more occurrence of the previous character, so in this case we match at least one numeric character, and at least one space, followed by a capital L.



                          -E is required to interpret the + as a special character instead of a literal '+'



                          output:



                          59 LOUIS 1202 +1
                          62 LEON 1137 +12
                          73 LUCA 973 -1





                          share|improve this answer






























                            2














                            2










                            2









                            Another grep example:



                            grep -E "[0-9]+ +L" file


                            + matches one or more occurrence of the previous character, so in this case we match at least one numeric character, and at least one space, followed by a capital L.



                            -E is required to interpret the + as a special character instead of a literal '+'



                            output:



                            59 LOUIS 1202 +1
                            62 LEON 1137 +12
                            73 LUCA 973 -1





                            share|improve this answer
















                            Another grep example:



                            grep -E "[0-9]+ +L" file


                            + matches one or more occurrence of the previous character, so in this case we match at least one numeric character, and at least one space, followed by a capital L.



                            -E is required to interpret the + as a special character instead of a literal '+'



                            output:



                            59 LOUIS 1202 +1
                            62 LEON 1137 +12
                            73 LUCA 973 -1






                            share|improve this answer















                            share|improve this answer




                            share|improve this answer








                            edited Oct 17 at 15:32

























                            answered Oct 17 at 7:42









                            F. ParetoF. Pareto

                            413 bronze badges




                            413 bronze badges
























                                1


















                                Avoid RegEx when possible. AWK example:



                                index($2, "L") == 1





                                share|improve this answer




























                                • Why do you think it's a bad idea to answer with a working example like awk 'index($2, "L") == 1' file like everybody else does?

                                  – Freddy
                                  Oct 17 at 0:30











                                • @Freddy I posted my code carefully and purposefully. Your code is a valid shell script, while mine is a valid AWK script. Please stop changing it.

                                  – user327359
                                  Oct 17 at 0:45











                                • I stopped changing it, I'm just curious. This question is tagged with sed and not everybody knows how to run your script, that's all.

                                  – Freddy
                                  Oct 17 at 0:50











                                • @Freddy its public information for at least 20 years now... pubs.opengroup.org/onlinepubs/007908799/xcu/awk.html

                                  – user327359
                                  Oct 17 at 1:54











                                • This is about as useful as answering with just oldfile newfile without bothering to mention cp, when someone asks "how do i copy a file?" and then snarkily pointing out that cp has been public information for decades. Actually, it's worse than that because "avoid regex when possible" is a terrible answer for a simple text processing problem.

                                  – cas
                                  Oct 21 at 4:53















                                1


















                                Avoid RegEx when possible. AWK example:



                                index($2, "L") == 1





                                share|improve this answer




























                                • Why do you think it's a bad idea to answer with a working example like awk 'index($2, "L") == 1' file like everybody else does?

                                  – Freddy
                                  Oct 17 at 0:30











                                • @Freddy I posted my code carefully and purposefully. Your code is a valid shell script, while mine is a valid AWK script. Please stop changing it.

                                  – user327359
                                  Oct 17 at 0:45











                                • I stopped changing it, I'm just curious. This question is tagged with sed and not everybody knows how to run your script, that's all.

                                  – Freddy
                                  Oct 17 at 0:50











                                • @Freddy its public information for at least 20 years now... pubs.opengroup.org/onlinepubs/007908799/xcu/awk.html

                                  – user327359
                                  Oct 17 at 1:54











                                • This is about as useful as answering with just oldfile newfile without bothering to mention cp, when someone asks "how do i copy a file?" and then snarkily pointing out that cp has been public information for decades. Actually, it's worse than that because "avoid regex when possible" is a terrible answer for a simple text processing problem.

                                  – cas
                                  Oct 21 at 4:53













                                1














                                1










                                1









                                Avoid RegEx when possible. AWK example:



                                index($2, "L") == 1





                                share|improve this answer
















                                Avoid RegEx when possible. AWK example:



                                index($2, "L") == 1






                                share|improve this answer















                                share|improve this answer




                                share|improve this answer








                                edited Oct 16 at 23:51

























                                answered Oct 16 at 21:39







                                user327359user327359






















                                • Why do you think it's a bad idea to answer with a working example like awk 'index($2, "L") == 1' file like everybody else does?

                                  – Freddy
                                  Oct 17 at 0:30











                                • @Freddy I posted my code carefully and purposefully. Your code is a valid shell script, while mine is a valid AWK script. Please stop changing it.

                                  – user327359
                                  Oct 17 at 0:45











                                • I stopped changing it, I'm just curious. This question is tagged with sed and not everybody knows how to run your script, that's all.

                                  – Freddy
                                  Oct 17 at 0:50











                                • @Freddy its public information for at least 20 years now... pubs.opengroup.org/onlinepubs/007908799/xcu/awk.html

                                  – user327359
                                  Oct 17 at 1:54











                                • This is about as useful as answering with just oldfile newfile without bothering to mention cp, when someone asks "how do i copy a file?" and then snarkily pointing out that cp has been public information for decades. Actually, it's worse than that because "avoid regex when possible" is a terrible answer for a simple text processing problem.

                                  – cas
                                  Oct 21 at 4:53

















                                • Why do you think it's a bad idea to answer with a working example like awk 'index($2, "L") == 1' file like everybody else does?

                                  – Freddy
                                  Oct 17 at 0:30











                                • @Freddy I posted my code carefully and purposefully. Your code is a valid shell script, while mine is a valid AWK script. Please stop changing it.

                                  – user327359
                                  Oct 17 at 0:45











                                • I stopped changing it, I'm just curious. This question is tagged with sed and not everybody knows how to run your script, that's all.

                                  – Freddy
                                  Oct 17 at 0:50











                                • @Freddy its public information for at least 20 years now... pubs.opengroup.org/onlinepubs/007908799/xcu/awk.html

                                  – user327359
                                  Oct 17 at 1:54











                                • This is about as useful as answering with just oldfile newfile without bothering to mention cp, when someone asks "how do i copy a file?" and then snarkily pointing out that cp has been public information for decades. Actually, it's worse than that because "avoid regex when possible" is a terrible answer for a simple text processing problem.

                                  – cas
                                  Oct 21 at 4:53
















                                Why do you think it's a bad idea to answer with a working example like awk 'index($2, "L") == 1' file like everybody else does?

                                – Freddy
                                Oct 17 at 0:30





                                Why do you think it's a bad idea to answer with a working example like awk 'index($2, "L") == 1' file like everybody else does?

                                – Freddy
                                Oct 17 at 0:30













                                @Freddy I posted my code carefully and purposefully. Your code is a valid shell script, while mine is a valid AWK script. Please stop changing it.

                                – user327359
                                Oct 17 at 0:45





                                @Freddy I posted my code carefully and purposefully. Your code is a valid shell script, while mine is a valid AWK script. Please stop changing it.

                                – user327359
                                Oct 17 at 0:45













                                I stopped changing it, I'm just curious. This question is tagged with sed and not everybody knows how to run your script, that's all.

                                – Freddy
                                Oct 17 at 0:50





                                I stopped changing it, I'm just curious. This question is tagged with sed and not everybody knows how to run your script, that's all.

                                – Freddy
                                Oct 17 at 0:50













                                @Freddy its public information for at least 20 years now... pubs.opengroup.org/onlinepubs/007908799/xcu/awk.html

                                – user327359
                                Oct 17 at 1:54





                                @Freddy its public information for at least 20 years now... pubs.opengroup.org/onlinepubs/007908799/xcu/awk.html

                                – user327359
                                Oct 17 at 1:54













                                This is about as useful as answering with just oldfile newfile without bothering to mention cp, when someone asks "how do i copy a file?" and then snarkily pointing out that cp has been public information for decades. Actually, it's worse than that because "avoid regex when possible" is a terrible answer for a simple text processing problem.

                                – cas
                                Oct 21 at 4:53





                                This is about as useful as answering with just oldfile newfile without bothering to mention cp, when someone asks "how do i copy a file?" and then snarkily pointing out that cp has been public information for decades. Actually, it's worse than that because "avoid regex when possible" is a terrible answer for a simple text processing problem.

                                – cas
                                Oct 21 at 4:53


















                                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%2f546934%2fextract-lines-from-files-with-names-begining-with-given-letter%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

                                Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її