Grep

Categories: Linux; Tagged with: ; @ May 8th, 2014 21:50

[email protected] /tmp $ grep ‘hi’ test1.txt
hi
hihihihi

# Display line number
[email protected] /tmp $ grep -n ‘hi’ test1.txt
3: hi
4:hihihihi

# Count
[email protected] /tmp $ grep -c ‘hi’ test1.txt
2

# Case insensitive
[email protected] /tmp $ grep -n -i ‘hi’ test1.txt
1: HI
2: Hi
3: hi
4:hihihihi

# Search the whole word
[email protected] /tmp $ grep -n -w ‘hi’ test1.txt
3: hi

# Search recursively
[email protected] /tmp $ grep -n -w ‘hi’ -r  test*
test1.txt:3: hi
test3:2:hi

# Use grep in Pipes
GDEV tmp # find . -name ‘test*’ |xargs grep ‘hi’
./test1.txt: hi
./test1.txt:hihihihi
./test2:Hi, this is test2;
./test3:this is test 3
./test3:hi

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.