Solved

grep

Posted on 2003-11-13
6
458 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
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…
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.:
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.

770 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