Get text from file matching specific line numbers?Print nth line before the matched line, Matching line and nth line from the matched lineHow to read a text file line by line which is not constant in shell scriptingShell program which reads line and output lines with the line numbersCreating a text file from other text filesGet specific line below grepped lineHow to execute a find command using a set of strings from a line in a text filematch specific line and print all lines except the following lineBash script Multiply only numbers from a text file?Need shell script to read line with matching contentFind and copy text from one file to another
What do you call someone who asks many questions?
Unlock My Phone! February 2018
How do I deal with an unproductive colleague in a small company?
Plagiarism or not?
How to show a landlord what we have in savings?
How to prevent "they're falling in love" trope
How writing a dominant 7 sus4 chord in RNA ( Vsus7 chord in the 1st inversion)
Is it inappropriate for a student to attend their mentor's dissertation defense?
Why are the 737's rear doors unusable in a water landing?
Assassin's bullet with mercury
Should I tell management that I intend to leave due to bad software development practices?
Why didn't Boeing produce its own regional jet?
Which is the best way to check return result?
Is "remove commented out code" correct English?
How badly should I try to prevent a user from XSSing themselves?
How does a predictive coding aid in lossless compression?
Im going to France and my passport expires June 19th
Can we compute the area of a quadrilateral with one right angle when we only know the lengths of any three sides?
Little known, relatively unlikely, but scientifically plausible, apocalyptic (or near apocalyptic) events
How seriously should I take size and weight limits of hand luggage?
Why didn't Miles's spider sense work before?
Avoiding the "not like other girls" trope?
A category-like structure without composition?
I would say: "You are another teacher", but she is a woman and I am a man
Get text from file matching specific line numbers?
Print nth line before the matched line, Matching line and nth line from the matched lineHow to read a text file line by line which is not constant in shell scriptingShell program which reads line and output lines with the line numbersCreating a text file from other text filesGet specific line below grepped lineHow to execute a find command using a set of strings from a line in a text filematch specific line and print all lines except the following lineBash script Multiply only numbers from a text file?Need shell script to read line with matching contentFind and copy text from one file to another
How can a script get the line number(s) of sentences with words length less than 20, then use those line numbers to get the text from another file with those line numbers?
awk 'if (NF<20) print NR' filename
will get sentences with length less than 20 words and print the line number, but how would a script use its output to get sentences matching those lines numbers from another file?
shell-script
New contributor
add a comment |
How can a script get the line number(s) of sentences with words length less than 20, then use those line numbers to get the text from another file with those line numbers?
awk 'if (NF<20) print NR' filename
will get sentences with length less than 20 words and print the line number, but how would a script use its output to get sentences matching those lines numbers from another file?
shell-script
New contributor
3
Please click edit then tell us what you have tried so far, and what the result was. Please also provide examples, as your question is not very understandable.
– K7AAY
2 days ago
3
Yes, do provide examples of data. Also, theawk
code you show will count words (by default these would be whitespace delimited strings) on the current line, not necessarily in a sentence.
– Kusalananda♦
2 days ago
add a comment |
How can a script get the line number(s) of sentences with words length less than 20, then use those line numbers to get the text from another file with those line numbers?
awk 'if (NF<20) print NR' filename
will get sentences with length less than 20 words and print the line number, but how would a script use its output to get sentences matching those lines numbers from another file?
shell-script
New contributor
How can a script get the line number(s) of sentences with words length less than 20, then use those line numbers to get the text from another file with those line numbers?
awk 'if (NF<20) print NR' filename
will get sentences with length less than 20 words and print the line number, but how would a script use its output to get sentences matching those lines numbers from another file?
shell-script
shell-script
New contributor
New contributor
edited 2 days ago
K7AAY
909928
909928
New contributor
asked 2 days ago
mocarsha2019mocarsha2019
12
12
New contributor
New contributor
3
Please click edit then tell us what you have tried so far, and what the result was. Please also provide examples, as your question is not very understandable.
– K7AAY
2 days ago
3
Yes, do provide examples of data. Also, theawk
code you show will count words (by default these would be whitespace delimited strings) on the current line, not necessarily in a sentence.
– Kusalananda♦
2 days ago
add a comment |
3
Please click edit then tell us what you have tried so far, and what the result was. Please also provide examples, as your question is not very understandable.
– K7AAY
2 days ago
3
Yes, do provide examples of data. Also, theawk
code you show will count words (by default these would be whitespace delimited strings) on the current line, not necessarily in a sentence.
– Kusalananda♦
2 days ago
3
3
Please click edit then tell us what you have tried so far, and what the result was. Please also provide examples, as your question is not very understandable.
– K7AAY
2 days ago
Please click edit then tell us what you have tried so far, and what the result was. Please also provide examples, as your question is not very understandable.
– K7AAY
2 days ago
3
3
Yes, do provide examples of data. Also, the
awk
code you show will count words (by default these would be whitespace delimited strings) on the current line, not necessarily in a sentence.– Kusalananda♦
2 days ago
Yes, do provide examples of data. Also, the
awk
code you show will count words (by default these would be whitespace delimited strings) on the current line, not necessarily in a sentence.– Kusalananda♦
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
FNR = File Number Record, is the current line number in the context of the current file
NR = Number Record, is the line number total
Passing both files to awk and using a comparison to detect the file change, this is going to store the line number of file1 in an array if the Field Number is less than 20 and print the line of file2 if it is in the array
awk 'FNR==NRif (NF<20) lines[NR]="1"; nextif (FNR in lines) print' file1 file2
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/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
);
);
mocarsha2019 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f509906%2fget-text-from-file-matching-specific-line-numbers%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
FNR = File Number Record, is the current line number in the context of the current file
NR = Number Record, is the line number total
Passing both files to awk and using a comparison to detect the file change, this is going to store the line number of file1 in an array if the Field Number is less than 20 and print the line of file2 if it is in the array
awk 'FNR==NRif (NF<20) lines[NR]="1"; nextif (FNR in lines) print' file1 file2
add a comment |
FNR = File Number Record, is the current line number in the context of the current file
NR = Number Record, is the line number total
Passing both files to awk and using a comparison to detect the file change, this is going to store the line number of file1 in an array if the Field Number is less than 20 and print the line of file2 if it is in the array
awk 'FNR==NRif (NF<20) lines[NR]="1"; nextif (FNR in lines) print' file1 file2
add a comment |
FNR = File Number Record, is the current line number in the context of the current file
NR = Number Record, is the line number total
Passing both files to awk and using a comparison to detect the file change, this is going to store the line number of file1 in an array if the Field Number is less than 20 and print the line of file2 if it is in the array
awk 'FNR==NRif (NF<20) lines[NR]="1"; nextif (FNR in lines) print' file1 file2
FNR = File Number Record, is the current line number in the context of the current file
NR = Number Record, is the line number total
Passing both files to awk and using a comparison to detect the file change, this is going to store the line number of file1 in an array if the Field Number is less than 20 and print the line of file2 if it is in the array
awk 'FNR==NRif (NF<20) lines[NR]="1"; nextif (FNR in lines) print' file1 file2
answered 2 days ago
DalvenjiaDalvenjia
1,23658
1,23658
add a comment |
add a comment |
mocarsha2019 is a new contributor. Be nice, and check out our Code of Conduct.
mocarsha2019 is a new contributor. Be nice, and check out our Code of Conduct.
mocarsha2019 is a new contributor. Be nice, and check out our Code of Conduct.
mocarsha2019 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f509906%2fget-text-from-file-matching-specific-line-numbers%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
Please click edit then tell us what you have tried so far, and what the result was. Please also provide examples, as your question is not very understandable.
– K7AAY
2 days ago
3
Yes, do provide examples of data. Also, the
awk
code you show will count words (by default these would be whitespace delimited strings) on the current line, not necessarily in a sentence.– Kusalananda♦
2 days ago