print or remove lines of a file
Show one line by its number, a range, skip the first ones, or take off the last.
text
steps
-
sed -n '5p' file.txtline 5
-
sed -n '5,10p' file.txtlines 5 to 10
-
tail -n +2 file.txteverything from line 2: skip a header
-
head -n 20 file.txtthe first 20 lines
-
tail -n 20 file.txtthe last 20 lines
-
sed -i '$d' file.txtremove the last line
-
head -n -5 file.txteverything but the last 5 lines (GNU)
commands used
sedheadtailawk
Each has a page in lore: lore sed opens it.
add up numbers in a file
Sum a column of numbers, from a file or a command's output.
compare two folders
Find which files differ between two folders, or are only in one of them.
count lines of code
How many lines of code a project has, in total and by language.
count lines, words and files
Count the lines of a file or of a command's output, the words, and the files in a folder.