Find and Grep - bra att ha ibland
------------------------------
grep -r --include="*.[ch]" pattern .
------------------------------
grep -RnisI <pattern> *
-R recurse into subdirectories
-n show line numbers of matches
-i ignore case
-s suppress "doesn't exist" and "can't read" messages
-I ignore binary files (technically, process them as having no matches, important for showing inverted results with -v)
#Search for a string inside all files in the current directory
------------------------------
comm -23 <(cut -f 3 -d , stuff1.csv | sort -i | uniq -i) <(cut -f 3 -d , stuff2.csv | sort -i | uniq -i)
stuff1.csv =
joe@example.com
jim@example.com
sally@example.com
stuff2.csv =
sally@example.com
#Jämför 2 filer och plocka ut de unika e-post adresserna som finns i stuff1.csv men inte i stuff2.csv
------------------------------
cut -f 3 -d , stuff.csv | sort --ignore-case | uniq --ignore-case
-f = 3:e kolumnen
-d = delimiter i filen stuff.csv
stuff.csv =
joe@example.com
jim@example.com
sally@example.com
joe@example.com
#Plocka ut alla unika e-post adresser ur filen stuff.csv.
-----------------------------------
sed '/^.*$/ !d ' 2.txt
#Sök fram rader i filen 2.txt som bara har ascii tecken men ta inte bort dessa (!d). Mycket bra för att rensa en wordlist på control tecken mm.
------------------------------
for i in $(cut -f 3 -d , stuff.csv | sort --ignore-case | uniq --ignore-case)
do
grep -F -i "$i" stuff.csv | head -n 1
done
#Sök fram HELA raden för de unika e-post adresserna som finns i filen stuff.csv
------------------------------
find . -name "*.txt" | xargs sed -i "s/old/new/"
#search and replace in files
------------------------------
grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
#Sök fram rader i filen 2.txt som bara har ascii tecken men ta inte bort dessa (!d). Mycket bra för att rensa en wordlist på control tecken mm.
------------------------------
for i in $(cut -f 3 -d , stuff.csv | sort --ignore-case | uniq --ignore-case)
do
grep -F -i "$i" stuff.csv | head -n 1
done
#Sök fram HELA raden för de unika e-post adresserna som finns i filen stuff.csv
------------------------------
find . -name "*.txt" | xargs sed -i "s/old/new/"
#search and replace in files
------------------------------
grep -2 -iIr "err\|warn\|fail\|crit" /var/log/*
#sök i logg
------------------------------
find . -name "*.[ch]" | xargs grep "TODO"
#grep certain file types recursively
------------------------------
find . -name "*.[ch]" | xargs grep "TODO"
#grep certain file types recursively
Inga kommentarer:
Skicka en kommentar