0% found this document useful (0 votes)
5 views2 pages

Task

Uploaded by

moizmalikt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Task

Uploaded by

moizmalikt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

GREP:

1.grep one number, multiple numbers, everything except one number


grep '0321' task1 / grep -E '0310|0345' task1 / grep -v '456' task1

2. grep case sensitive/insensitive character


grep ' multiple ' task2/ grep -i arch task2

3.grep specific files with patterns


grep 'sent sms' test.log (for a single file )/ grep sent sms *.txt(this command
search in all txt files in a directory)/ grep -l 'error'*.log (This will list
all .log files that contain the word "error")

4.use grep to look for files which contains the word for instance 'HTTP'
grep -r 'http' /etc (is used to search for the pattern 'http' within all files and
subdirectories under the /etc directory recursively)

5.use grep to count numbers having prefix 0301,0302


grep -cE "0301|0302" task1

6.grep two lines of trailing context after each match


grep -A 3 support task2 /( this will display three lines after a first "suppot"
match pattern)

7.grep two lines of leading context before each match


grep -B 2 'linux' filename (this will display match pattarn line and also 2 before
lines)

8. grep two lines of leading and trailing context surrounding each match
grep -c 2 'support' task2 ( this will match pattarn and print line and also print
two lines after and before lines of a matched pattern line)

VIM COMMAND:

1. copy pasting, syntaxing, search and replace and etc


/linux (for search pattern) / :s/Linux/unix/(for replace) / :%s/Linux/unix/g (for
change in all file)

2.search a number in file


/03345555777

3.replace 92 from start of every number

:%s/0306/92/g
4.replace 0 from start of every number with 921
:%s/0/921/g

5.add "Ufone" at the end of every number


:%s/\v(\d+)/\0Ufone/g

6.add "Ufone" at the start of every number


:%s/\v(\d+)/Ufone\0/g

grep sed awk

1. Each line starts with datetime then log type, count 'Sent SMS' logs.
grep -c 'Sent SMS' test.log
2.Get output which contains the first 10 'Sent SMS' logs on terminal
grep 'Sent SMS' test.log | head -n 10

3.Get output which contains the first 25 'Sent SMS' logs on terminal.
grep 'Sent SMS' test.log | head -n 25

4.Get output which contains the last 15 'Sent SMS' logs on terminal
grep 'Sent SMS' test.log | tail -n 15

5.Count of lines this file contains


awk 'END {print NR}' test.log

You might also like