| | |
grep command help
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 16
Reputation:
Solved Threads: 0
I have the following information in the text file:
1:boot
2:book
3:booze
4:machine
5:boots
6:bungie
7:bark
8:aardvark
9:broken$tuff
10:robots
11:rebine
when i did a grep -n "b*" a_file.txt, it returned
1:boot
2:book
3:booze
4:machine
5:boots
6:bungie
7:bark
8:aardvark
9:broken$tuff
10:robots
11:rebine
I thought it would match the letter b followed by anything. But why is line 4,8,10,11 appearing since its not starting with letter B? I actually quite confused how to correctly use the * wildcard.
I have made a search online, and found that, if i wanted to search for anything that starts with the letter b, i should instead do a grep -n "^b" a_file.txt.
Anyone can explain to me what grep -n "b*" a_file.txt does? as in, "b*". I can't understand how it is matched.
Many thanks.
1:boot
2:book
3:booze
4:machine
5:boots
6:bungie
7:bark
8:aardvark
9:broken$tuff
10:robots
11:rebine
when i did a grep -n "b*" a_file.txt, it returned
1:boot
2:book
3:booze
4:machine
5:boots
6:bungie
7:bark
8:aardvark
9:broken$tuff
10:robots
11:rebine
I thought it would match the letter b followed by anything. But why is line 4,8,10,11 appearing since its not starting with letter B? I actually quite confused how to correctly use the * wildcard.
I have made a search online, and found that, if i wanted to search for anything that starts with the letter b, i should instead do a grep -n "^b" a_file.txt.
Anyone can explain to me what grep -n "b*" a_file.txt does? as in, "b*". I can't understand how it is matched.
Many thanks.
![]() |
Similar Threads
- python and bash (Python)
- Limiting grep searches to a given file type? (IT Professionals' Lounge)
- grep '^[a-zA-Z]' (Shell Scripting)
- c doubts (C++)
- Using Grep (*nix Software)
- derive full name of user and grep search count (Shell Scripting)
- Help with SED/AWK email parser (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: copying multiple files with user input
- Next Thread: Shell script help
Views: 906 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting






