Solved

grep

Posted on 2003-11-13
6
447 Views
Last Modified: 2010-04-21
I have this as my file (myfile) contents
myfile
====
aaaa
bbbb
cccc
dddd

Then i do this
  grep "*a" myfile
but then i still get all the lines! I wished to get the first line only.

How can that be?
0
Comment
Question by:cutie2000
  • 3
  • 2
6 Comments
 

Author Comment

by:cutie2000
ID: 9738659
a good tutorial on grep regular expressions would be good.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9738676
Hi cutie2000,

in grep regex * means 0 or more instances ... thus everything qualifies....
read grep man page... the regex in grep are slightly different from shell regex

to get only first line, use
grep aaaa myfile   :D

Cheers!
Sunny:o)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9738680
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:cutie2000
ID: 9739160
then wouldn't * be useless since it does not perform any grep?
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 25 total points
ID: 9739191
no... it has its own use, how it behaves depends on how you use ;o) ...I suggest you look at the man page and tutorial carefully ... here is an example from the tutorial

Examples: Wildcards
The File for These Examples
>cat file
big
bad bug
bag
bigger
boogy

 Wildcards #1
>grep "b.*g" file
big
bad bug
bag
bigger
boogy

 Wildcards #2
>grep "b.*g." file
bigger
boogy

 Wildcards #3
>grep "ggg*" file
bigger

 
0
 
LVL 3

Assisted Solution

by:Ravi Goru
Ravi Goru earned 25 total points
ID: 9872626
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now