How to use grep properly?

ismaeel_ali

New Member
Joined
Nov 10, 2019
Messages
1
Reaction score
0
Credits
0
Hi all,

I have been given the homework to complete a bunch of searches using the grep command. However, my teacher did not explain it that well... Could someone perhaps explain how i should go about doing it?

1) "In the ‘searching’ folder, search the ‘countries’ file for all entries containing ‘j’. Write the output to a file called ‘output’ in the searching directory. What is the token displayed?"
2) "Inside the ‘searching’ folder, search the ‘countries’ file for all entries containing the word ‘united’. Write the output to a file call ‘united’ in the searching directory. What is the token displayed?"
3) "Inside the ‘searching’ folder, sort the ‘countries’ file in reverse order and write the output to a file call ‘yrtnuoc’ in the searching directory. What is the token displayed?"
 


let me give you an example of basic use of grep combined with ls command.

I use it to drill down to find if I have package in my /var/log/packages directory

i'm using grep from command line on a linux terminal

By default when i open a terminal , its working on the basis that it is in my home folder. But i want to list packages that have a name matching packages in /var/log/packages

so i write ls /var/log/packages/ | grep audacity

i get returned audacity-2.3.2-x86_64-1_SBo

what i did is use "list" command which is : ls

then folder i want to search : /var/log/packages

use pipe command to pass it through grep : |

then give it a key word to search audacity

so you can do something similar

if you have windows 10 you can install Linux and have access to command- i don't use windows but saw that possibility, or if you have access to a linux computer , juts open a terminal .I guess the idea of "homework" is to make you "do" the theory they talked about -so give it a go :)

oh for output you can do

/var/log/packages/ | grep audacity -> somefile.txt

come back with your experiences !
 
Last edited:

Members online


Top