【2018.04.29 Study Notes】【Extended knowledge of regular expressions】

Regular Expressions Extended Knowledge Exercise

  1. How to print out the lines with user uid greater than 500 in /etc/passwd? uid is the third paragraph of the file passwd, so: awk -F ':' '$3>500 {print $0}' passwd

  2. What is the meaning of the two variables NR and NF in awk? What will awk -F ':' '{print $NR}' /etc/passwd print out? NR represents the line number, and NF represents the number of segments of the line. Print result: print the nth paragraph of the nth line of passwd in sequence.

  3. Use grep to filter out the lines containing 'abc' or '123' in the 1.txt document, and add the line number in front of the filtered line. grep -n 'abc|123' 1.txt

  4. grep -v '^$' 1.txt Which lines will this filter out? ^$ represents an empty line, so -v is negated to filter out all non-empty lines.

  5. What do '.' ' ' and '. ' mean respectively? What do '+' and '?' mean, can these five symbols be used in grep, and can they be used in egrep, sed and awk? . means match a single arbitrary character * means match 0 or more arbitrary characters. * means match empty character or any string + means match 1 or more arbitrary characters? means match 0 or 1 arbitrary character. Can be used in grep, egrep, sed, awk

  6. A {} is used in grep, what is it used for? Indicates the number of consecutive occurrences of the preceding character, and the numbers in curly brackets represent the number of occurrences.

  7. sed has an option to change text files directly, which option is it? -i selects to modify the original file directly.

  8. sed -i 's/ .ie//;s/["|&]. //' file What does this command mean?

  9. How to delete all numbers or letters in a document? sed 's/[0-9-a-zA-Z]//g'file , replace numbers and letters with empty characters

  10. Intercept the first segment of log 1.log (separated by spaces), sort by numbers, and then remove duplicates, but how to keep the number of duplicates?

  11. Use awk to filter out the lines in 1.log where the 7th paragraph (space separated) is '200' and the 8th paragraph is '11897'.

  12. Please compare the similarities and differences of these two commands: grep -v '^[0-9]' 1.txt and grep '^[^0-9]' 1.txt

  13. What does $0 in awk mean? Why are the $0 results of the following two commands inconsistent? awk -F ':' '{print $0}' 1.txt and awk -F ':' '$7=1 {print $0}' 1.txt

  14. When using grep to filter a certain keyword, how to print the line containing the keyword together with the upper line, and the lower line? Print both the top and bottom at the same time?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325175326&siteId=291194637