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
A category-like structure without composition?
How does a predictive coding aid in lossless compression?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Should I cover my bicycle overnight while bikepacking?
Short story with a alien planet, government officials must wear exploding medallions
Could the museum Saturn V's be refitted for one more flight?
Im going to France and my passport expires June 19th
Is "remove commented out code" correct English?
Can I run a new neutral wire to repair a broken circuit?
Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?
How to tell a function to use the default argument values?
How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)
Venezuelan girlfriend wants to travel the USA to be with me. What is the process?
Reverse dictionary where values are lists
Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?
I would say: "You are another teacher", but she is a woman and I am a man
Detention in 1997
Watching something be piped to a file live with tail
Why is consensus so controversial in Britain?
How did the Super Star Destroyer Executor get destroyed exactly?
How to Recreate this in LaTeX? (Unsure What the Notation is Called)
Cursor Replacement for Newbies
Can a virus destroy the BIOS of a modern computer?
How could indestructible materials be used in power generation?
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