Musím simulovať egrep
plus niektoré možnosti s inými príkazmi, hlavne awk
, ale naozaj nerozumiem, ako to urobiť v scenári. Viem to awk
rozpoznáva regulárne výrazy, ale môže to byť náhrada za egrep
?
Naozaj neviem, kde začať.
odpovede:
3 pre odpoveď č. 1Použitý vzorový súbor:
[jaypal:~/Temp] cat file
This is FirstLine
SecondLineEEE
AAAblablabla
ForthLineEEE
FifthLine
LastLine
simulácie:
1. egrep -n
[jaypal:~/Temp] egrep -n "LastLine" file
6:LastLine
[jaypal:~/Temp] awk /LastLine/"{print NR":"$0}" file
6:LastLine
2. egrep -v
[jaypal:~/Temp] egrep -v "LastLine" file
This is FirstLine
SecondLineEEE
AAAblablabla
ForthLineEEE
FifthLine
[jaypal:~/Temp] awk "/LastLine/{next}1" file
This is FirstLine
SecondLineEEE
AAAblablabla
ForthLineEEE
FifthLine
alebo (ako uvádza Dennis v komentároch)
[jaypal:~/Temp] awk "!/LastLine/" file
This is FirstLine
SecondLineEEE
AAAblablabla
ForthLineEEE
FifthLine
3. egrep -i
(Toto je iba v gnu awk
)
[jaypal:~/Temp] egrep -i "lastline" file
LastLine
[jaypal:~/Temp] gawk -v IGNORECASE=1 "/lastline/" file
LastLine
4. egrep -w
(Toto je iba v gnu awk
)
[jaypal:~/Temp] egrep -w "is" file
This is FirstLine
[jaypal:~/Temp] gawk "/<is>/" file
This is FirstLine
5. egrep -f
[jaypal:~/Temp] cat file
This is FirstLine
SecondLineEEE
AAAblablabla
ForthLineEEE
FifthLine
LastLine
[jaypal:~/Temp] cat patternfile
LastLine
is
[jaypal:~/Temp] egrep -f patternfile file
This is FirstLine
LastLine
[jaypal:~/Temp] awk "NR==FNR{a[$0]++;next} {for (x in a) if ($0~x) print $0}" patternfile file
This is FirstLine
LastLine