Text Manipulation Flashcards
How to use the sed command to find and replace all the occurences of the term ‘mysql’ for ‘MySQL’ in a file called details.conf?
$ sed s/mysql/MySQL/g details.conf > details.conf
How to use the sed command to find and replace only the first occurence of the term ‘mysql’ for ‘MySQL’ in a file called details.conf?
$ sed s/mysql/MySQL/ details.conf > details.conf
How to use the sed command to find and replace only the second occurence of the term ‘mysql’ for ‘MySQL’ in a file called details.conf?
$ sed s/mysql/MySQL/2 details.conf > details.conf
How do you display a file with line numbers?
Using the nl command.
How do you show only the first 20 lines of a file called text_file.txt?
$ head -20 text_file.txt
How do you show the last 20 lines of a file called text_file.txt?
$ tail -20 text_file.txt
Why is the cat command not so good to display large files?
Because it prints all the file at once in the console making it not so practical to glean any information from it.
What utility does the man command use?
The “more” command.
What is the difference between “more” and “less” commands?
Both are used to display files page by page, but less has an additional functionality that permits filtering the text for terms.
After typing a term while seeing a file with less, how can you go to the next occurence of the searched term?
By pressing n.