Difference between revisions of "Introduction to Linux in HPC/Text display search"
Introduction to Linux in HPC/Text display search
Jump to navigation
Jump to search
Line 48: | Line 48: | ||
{ | { | ||
|type="()"} | |type="()"} | ||
− | - command > filename | + | - <code>command > filename</code> |
|| | || | ||
− | + command >> filename | + | + <code>command >> filename</code> |
− | || Explanation: The > operator redirects the output of command into filename. If filename exists already, its contents will be overwritten. The >> operator can redirect the output of command into filename as well, except that if filename exists, the new data are appended instead of overwritten. | + | || Explanation: The <code>></code> operator redirects the output of command into filename. If filename exists already, its contents will be overwritten. The <code>>></code> operator can redirect the output of command into filename as well, except that if filename exists, the new data are appended instead of overwritten. |
</quiz> | </quiz> | ||
{{hidden end}} | {{hidden end}} | ||
Line 57: | Line 57: | ||
{{hidden begin | {{hidden begin | ||
|title = 2. How do I find all files containing specific text on Linux? </br> | |title = 2. How do I find all files containing specific text on Linux? </br> | ||
− | HINT: use grep command | + | HINT: use <code>grep</code> command |
}} | }} | ||
<quiz display=simple> | <quiz display=simple> | ||
Line 63: | Line 63: | ||
|type="()"} | |type="()"} | ||
+ Click and submit to see the answer | + Click and submit to see the answer | ||
− | || grep -rnw '/path/to/somewhere/' -e 'pattern' | + | || <code>grep -rnw '/path/to/somewhere/' -e 'pattern'</code> |
|| -r or -R is recursive, | || -r or -R is recursive, | ||
|| -n is line number, and | || -n is line number, and | ||
Line 75: | Line 75: | ||
{{Warning|mode=warn|text= '''no warnings in this section'''}} | {{Warning|mode=warn|text= '''no warnings in this section'''}} | ||
− | |||
=== Exercises in Terminal (slide 65) === <!--T:5--> | === Exercises in Terminal (slide 65) === <!--T:5--> |
Revision as of 10:44, 2 October 2020
Video
Linux Introduction Slides 58 - 64 (7 pages)
Slide Layout
page 1: grep command and syntax important options: -r, -i and -I page 2: many commands to display text cat less head and tail page 3: 40 sec console has three streams stdin stdout stderr page 4: stream in computing terms similar to streaming video input/output stream in console page 5: input/output streams can be redirected redirect stdout redirect stdin pipe page 6: stream append redirection numbered streams: 0 for stdin, 1 for stdout, 2 for stderr page 7: use grep to search piped output text
Quiz
1. Which command can be used to append text to filename?
2. How do I find all files containing specific text on Linux?
HINT: use
HINT: use
grep
command
Info: | no tips in this section |
Warning: | no warnings in this section |
Exercises in Terminal (slide 65)
1. Create a file using cat (some filename) and write some text in it as below. than use grep to find and display the line number and the line with the word Alan in the file. the best way to predict the future is to invent it – Alan Kay
Answer: |
$ cat > quote.txt <<"EOF" \ > the best way to predict \ > the future is to invent it > - Alan Kay > EOF EOF mean end of file. Press enter to get a new line while writing text. With cat > filename you write the file content in the file quote.txt. Further use grep as below $ grep -in alan quote.txt 3: - Alan Kay grep command option - - i to ignore case distinctions, so that characters that differ only in case match each other. - n for line number |