Text Manipulation Flashcards
How do you display the first 5 lines of a file?
head -n 5 file.extension
How do you display the last 3 lines of a file?
tail -n 3 file.extension
How do you display the output of a file starting from line 2?
tail -n +2 file.extension
How do you sort a file by alphabetical order?
sort file.extension
How do you sort a file by alphabetical order but in reverse order?
sort -r file.extension
How do you display the first 3 letters of ever line in a file?
cut -c 1-3 file.extension
What does grep “ap[pe]” file.extension do?
Returns any lines that contain the characters “app” or “ape”
What does grep “.ap” file.extension do?
Returns any lines that contain the characters any character, followed by “ap”
What does grep “ap*l” file.extension do?
Returns any lines that contain characters “a”, followed by p, followed by p (0 or more) and l
What does grep -E “el?o” file.extension do?
Returns any lines that contain characters that starts with an “e”, followed by “l”, followed by an “l” (optional), and ends in a “o”
How do you get the word count of a document?
wc -l file.extension