Lets see first 2 questions answers:
1. use grep to count the number of lines in a file(wc -l).ok, little tricky. you should match for a newline character(\n). or, simply, we can match for everything between ^ (beginning of the line) and $(end of the line)
and count the number of matches (-c)
invent@sekar - [/home/sekar/learning]
# cat grep-test-file1
hi123
hello111
invent@sekar - [/home/sekar/learning]
# grep -c '^.*$' grep-test-file1
2
invent@sekar - [/home/sekar/learning]
2. use grep to open a file like cat. ie, using grep, replicate the "cat filename" task (try both versions - grep and egrep)
simple. match for everything on the given file.
grep * filename --- will not work. single quote or double quote needed.
invent@sekar - [/home/sekar/learning]
# grep '*' grep-test-file
invent@sekar - [/home/sekar/learning]
# grep "*" grep-test-file
invent@sekar - [/home/sekar/learning]
# grep -e * grep-test-file (u know y this didnt work, right)
invent@sekar - [/home/sekar/learning]
# grep -e "*" grep-test-file ;# (egrep match for everything)
hi123
hello123 456
invent@sekar - [/home/sekar/learning]
# grep ".*" grep-test-file ;# (grep match for everything)
hi123
hello123 456
invent@sekar - [/home/sekar/learning]
grep "." grep-test-file --- will it work? analyze and try this please..
1. use grep to count the number of lines in a file(wc -l).ok, little tricky. you should match for a newline character(\n). or, simply, we can match for everything between ^ (beginning of the line) and $(end of the line)
and count the number of matches (-c)
invent@sekar - [/home/sekar/learning]
# cat grep-test-file1
hi123
hello111
invent@sekar - [/home/sekar/learning]
# grep -c '^.*$' grep-test-file1
2
invent@sekar - [/home/sekar/learning]
2. use grep to open a file like cat. ie, using grep, replicate the "cat filename" task (try both versions - grep and egrep)
simple. match for everything on the given file.
grep * filename --- will not work. single quote or double quote needed.
invent@sekar - [/home/sekar/learning]
# grep '*' grep-test-file
invent@sekar - [/home/sekar/learning]
# grep "*" grep-test-file
invent@sekar - [/home/sekar/learning]
# grep -e * grep-test-file (u know y this didnt work, right)
invent@sekar - [/home/sekar/learning]
# grep -e "*" grep-test-file ;# (egrep match for everything)
hi123
hello123 456
invent@sekar - [/home/sekar/learning]
# grep ".*" grep-test-file ;# (grep match for everything)
hi123
hello123 456
invent@sekar - [/home/sekar/learning]
grep "." grep-test-file --- will it work? analyze and try this please..
No comments:
Post a Comment