Main Menu

Search

Showing posts with label linux grep commands. Show all posts
Showing posts with label linux grep commands. Show all posts

LINUX: Command To Print All Characters In Lines After "/" BackSlash (Grep)

Below is the grep command to use.

grep -o '/[^/]*$' <filename> | cut -c2-

For e.g. if contents of file is as follows:

/registry/pods/kube-system/kube-flannel-ds-abcde
/registry/pods/kube-system/kube-flannel-ds-xyzab

Above command will print below

kube-flannel-ds-abcde
kube-flannel-ds-xyzab

LINUX: GREP COMMAND TO SEARCH FOR STRING IN THE FIND COMMAND RESULTS

Below command searches for all *.txt files in current working directory and then searches for “test-string” word in the file.

find . -name *.txt | xargs grep “test-string"

Below is sample Output.

 ./test.txt:             Port Name: test-string

 Or alternatively below command can also be used. Replace /var/log/messages* with filename pattern and restart with search string as needed.

for i in $(ls -art /var/log/messages*);do strings $i|grep 'restart';done 


Products to which Article Applies

All Linux Operating Systems 

Search Keywords: Linux Unix Grep command commands grepping greping search searching string words file files strings directory directories list listing

Article Author: Tarun Boyella

 

LINUX - GREP COMMANDS - CHEAT SHEET

 
GREP Command to list the first occurrence of search pattern testing in filename.txt
 
grep –m 1 testing filename.txt
 
 

Products to which Article Applies

All Linux OS’s

Search Keywords:  grep pattern matching match search searching cheatsheet cheat sheet cheetsheet cheet find finding command

Article Author: Tarun Boyella