Show certain lines by line number: Difference between revisions

Jump to navigation Jump to search
m
Tags: Mobile edit Mobile web edit
 
(2 intermediate revisions by one other user not shown)
Line 9: Line 9:
echo "line 5" >> test.txt
echo "line 5" >> test.txt
echo "line 6" >> test.txt
echo "line 6" >> test.txt
</pre>
key-in the command {{kbd | key=cat test.txt}} to view the file content
<pre>
line 1
line 2
line 3
line 4
line 5
line 6
</pre>
</pre>


== Approaches ==
== Approaches ==
=== Using cat, head & tail commands ===
=== Approach 1: Using cat, head & tail commands ===
1. key-in the command<ref>[https://unix.stackexchange.com/questions/288521/with-the-linux-cat-command-how-do-i-show-only-certain-lines-by-number text processing - With the Linux "cat" command, how do I show only certain lines by number - Unix & Linux Stack Exchange]</ref>
1. key-in the command<ref>[https://unix.stackexchange.com/questions/288521/with-the-linux-cat-command-how-do-i-show-only-certain-lines-by-number text processing - With the Linux "cat" command, how do I show only certain lines by number - Unix & Linux Stack Exchange]</ref>
<pre>
<pre>
Line 47: Line 57:
</pre>
</pre>


=== Using sed command ===
=== Approach 2: Using sed command ===
key-in the command<ref>[https://www.gnu.org/software/sed/manual/sed.html#Common-Commands sed, a stream editor]</ref>
key-in the command<ref>[https://www.gnu.org/software/sed/manual/sed.html#Common-Commands sed, a stream editor]</ref>
<pre>
<pre>
Line 70: Line 80:
[[Category:Linux]]
[[Category:Linux]]
[[Category:Data Science]]
[[Category:Data Science]]
[[Category:Text file processing]]
[[Category:String manipulation]]
Anonymous user

Navigation menu