Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

grep

Posted on 2003-11-13
6
Medium Priority
?
471 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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 100 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 100 total points
ID: 9872626
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

597 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