[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

regular expression

Posted on 2004-10-08
11
Medium Priority
?
347 Views
Last Modified: 2010-04-20
I have a file

My File
----
This is me, yeah
My number is 12 3
Hello world
hi are you ok?
I am king
no problem.


I like to have a grep regular expression that will give me lines with a-z, A-Z, commas, and blanks. That's my output should be

This is me, yeah
Hello world
I am king


cat myfile | grep ???????
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
  • 6
  • 3
  • 2
11 Comments
 
LVL 10

Expert Comment

by:Luxana
ID: 12257834
cat myfile | grep [.,H]
0
 

Author Comment

by:cutie2000
ID: 12257859
thanks for replying but then it's not what I wanted.
I need to give me lines with a-z, A-Z, commas, or blanks. Any other characters will be ignored. Sorry for the confusion
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12257917
>a-z, A-Z, commas, or blanks

this expresion will match every lines uper and lower case also , . and then your output will be all lines . Because a-z A-Z mach every letter and in your input we have letters on each line then the output will look like this:

cat myfile | grep [.,a-zA-Z]
This is me, yeah
My number is 12 3
Hello world
hi are you ok?
I am king
no problem.


expresion a-z and A-Z match each line !!!

0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 10

Expert Comment

by:Luxana
ID: 12257970
grep [.,H] myfile
This is me, yeah
Hello world
no problem.

grep reads each line in file and if your expresion match to line it will be printed out.

even space is on each line:

grep [" "] myfile
This is me, yeah
My number is 12 3
Hello world
hi are you ok?
I am king
no problem.
0
 

Author Comment

by:cutie2000
ID: 12258132
it won't work. i need not only accept space.
i need to accept space, alphabets and comma
lines with illegal characters will not be printed
hope it's clear
0
 
LVL 2

Expert Comment

by:Matt_Avery
ID: 12258342

grep '^[a-z,A-Z,0-9,\.\,]*$'


(match any string where every character ("*") between the start of the string ("^") and the end ("$") is alphanumeric, space, comma or fullstop ([a-z,A-Z,0-9\.\,])
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12258385
>i need to accept space, alphabets and comma

this match every line in file, so all of them will be printed out.
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12258453
to Matt:

grep '^[a-z,A-Z,0-9,\.\,]*$'

this mach all lines which starts with a-z A-Z number . or ,

you wanted probably:

grep '[a-z,A-Z,0-9,\.\,]'
0
 
LVL 2

Accepted Solution

by:
Matt_Avery earned 160 total points
ID: 12258454

Silly me - question said "A-z,a-z, commas and blanks"

So I should have said:

grep '^[a-z,A-Z, \,]*$'
0
 
LVL 2

Expert Comment

by:Matt_Avery
ID: 12258629
Luxana,

The original poster wanted a RE to match all lines that contain *only* characters from a certain set.

That's why I'm using '^[xyz]*$'  instead of just '[xyz]'

'[xyz]' would match all lines that contain *any* characters from a certain set.

 
0
 
LVL 10

Expert Comment

by:Luxana
ID: 12258697
matt

I understand that but I been confused with question:))

>I like to have a grep regular expression that will give me lines with a-z, A-Z, commas, and blanks.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Fine Tune your automatic Updates for Ubuntu / Debian
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

649 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