Solved

grep

Posted on 2003-11-13
6
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Fine Tune your automatic Updates for Ubuntu / Debian
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

717 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