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;
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
add a comment
|
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
3
Does theL
need to be in the second column? How are columns defined (spaces? tabs?)? Can theL
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 contains80 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 usesed
?
– Christopher Schultz
Oct 18 at 19:00
add a comment
|
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
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
text-processing sed regular-expression
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 theL
need to be in the second column? How are columns defined (spaces? tabs?)? Can theL
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 contains80 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 usesed
?
– Christopher Schultz
Oct 18 at 19:00
add a comment
|
3
Does theL
need to be in the second column? How are columns defined (spaces? tabs?)? Can theL
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 contains80 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 usesed
?
– 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
add a comment
|
6 Answers
6
active
oldest
votes
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
add a comment
|
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
awk 'substr($2, 1, 1) == "L"' file
would also work
– glenn jackman
Oct 15 at 19:59
@glennjackman Are there any benifits to usingsubstr
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
add a comment
|
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
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
add a comment
|
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.
add a comment
|
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
add a comment
|
Avoid RegEx when possible. AWK example:
index($2, "L") == 1
Why do you think it's a bad idea to answer with a working example likeawk '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 withsed
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 justoldfile newfile
without bothering to mentioncp
, 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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment
|
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
add a comment
|
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
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
answered Oct 15 at 18:36
Renan41Renan41
665 bronze badges
665 bronze badges
add a comment
|
add a comment
|
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
awk 'substr($2, 1, 1) == "L"' file
would also work
– glenn jackman
Oct 15 at 19:59
@glennjackman Are there any benifits to usingsubstr
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
add a comment
|
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
awk 'substr($2, 1, 1) == "L"' file
would also work
– glenn jackman
Oct 15 at 19:59
@glennjackman Are there any benifits to usingsubstr
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
add a comment
|
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
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
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 usingsubstr
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
add a comment
|
awk 'substr($2, 1, 1) == "L"' file
would also work
– glenn jackman
Oct 15 at 19:59
@glennjackman Are there any benifits to usingsubstr
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
add a comment
|
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
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
add a comment
|
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
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
add a comment
|
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
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
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
add a comment
|
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
add a comment
|
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.
add a comment
|
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.
add a comment
|
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.
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.
answered Oct 16 at 18:20
user800user800
3811 gold badge3 silver badges14 bronze badges
3811 gold badge3 silver badges14 bronze badges
add a comment
|
add a comment
|
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
add a comment
|
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
add a comment
|
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
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
edited Oct 17 at 15:32
answered Oct 17 at 7:42
F. ParetoF. Pareto
413 bronze badges
413 bronze badges
add a comment
|
add a comment
|
Avoid RegEx when possible. AWK example:
index($2, "L") == 1
Why do you think it's a bad idea to answer with a working example likeawk '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 withsed
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 justoldfile newfile
without bothering to mentioncp
, 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
add a comment
|
Avoid RegEx when possible. AWK example:
index($2, "L") == 1
Why do you think it's a bad idea to answer with a working example likeawk '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 withsed
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 justoldfile newfile
without bothering to mentioncp
, 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
add a comment
|
Avoid RegEx when possible. AWK example:
index($2, "L") == 1
Avoid RegEx when possible. AWK example:
index($2, "L") == 1
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 likeawk '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 withsed
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 justoldfile newfile
without bothering to mentioncp
, 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
add a comment
|
Why do you think it's a bad idea to answer with a working example likeawk '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 withsed
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 justoldfile newfile
without bothering to mentioncp
, 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
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
3
Does the
L
need to be in the second column? How are columns defined (spaces? tabs?)? Can theL
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