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
Examples of smooth manifolds admitting inbetween one and a continuum of complex structures
How do conventional missiles fly?
How dangerous is XSS?
Alternative to sending password over mail?
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
In 'Revenger,' what does 'cove' come from?
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
Is there a hemisphere-neutral way of specifying a season?
What about the virus in 12 Monkeys?
How much of data wrangling is a data scientist's job?
Expand and Contract
Do UK voters know if their MP will be the Speaker of the House?
Why didn't Boeing produce its own regional jet?
Watching something be piped to a file live with tail
All in one piece, we mend holes in your socks
Why doesn't using multiple commands with a || or && conditional work?
Arrow those variables!
Why is this clock signal connected to a capacitor to gnd?
What is the most common color to indicate the input-field is disabled?
How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)
What is a romance in Latin?
Little known, relatively unlikely, but scientifically plausible, apocalyptic (or near apocalyptic) events
Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?
Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?
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