Regular Expressions Extended Knowledge Exercise
-
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
-
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.
-
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
-
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.
-
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
-
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.
-
sed has an option to change text files directly, which option is it? -i selects to modify the original file directly.
-
sed -i 's/ .ie//;s/["|&]. //' file What does this command mean?
-
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
-
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?
-
Use awk to filter out the lines in 1.log where the 7th paragraph (space separated) is '200' and the 8th paragraph is '11897'.
-
Please compare the similarities and differences of these two commands: grep -v '^[0-9]' 1.txt and grep '^[^0-9]' 1.txt
-
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
-
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?