Solved

grep

Posted on 2003-11-13
6
462 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

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.

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

820 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