Horje
how to grep lines before a pattern Code Example
how to grep lines before a pattern
cat abc.txt | grep -B 3 "your_pattern"  #  will grep 3 lines bofore your pattern..
cat abc.txt | grep -A 3 "your_pattern"  # will grep 3 lines after your pattern..
tac abc.txt | grep -A 3 "your_pattern" # will grep 3 lines bofore your pattern..
cat abc.txt | grep -B 3 -A 3 "your_pattern"  
tac is upside down of the file , cat - tac



$ cat testing
aaa
11
21
31
41
51
aaa
12
22
32
42
51
aaa
13
23
33
33
43
53
aaa

$ cat testing | grep -A 2 aaa
aaa
11
21
--
aaa
12
22
--
aaa
13
23
--
aaa

tac testing | grep -A 2 aaa
aaa
53
43
--
aaa
82
72
--
aaa
61
51
--
aaa









Shell

Related
bash basename Code Example bash basename Code Example
shutdown heroku app Code Example shutdown heroku app Code Example
laravel remote: error: unable to unlink old 'public/.htaccess': Permission denied Code Example laravel remote: error: unable to unlink old 'public/.htaccess': Permission denied Code Example
install aws cli mac Code Example install aws cli mac Code Example
serverless not using aws profile Code Example serverless not using aws profile Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
14