Sponsored Content
Top Forums UNIX for Dummies Questions & Answers correct syntax for using "grep regex filename" ? Post 74807 by yongho on Monday 13th of June 2005 02:26:26 PM
Old 06-13-2005
correct syntax for using "grep regex filename" ?

I'm trying to grep a long ls by looking at the beginning of each filename for example:

Many files begin with yong_ho_free_2005...
Many files begin with yong_ho_2005...

I can't just use "grep yong_ho" otherwise It'll display both files.
So I'm trying to use a regex but my syntax is wrong.

ls -al | grep '^yong_ho_[1-9]'

This displays no matches.
Anyone know what I'm doing wrong?

It works if I remove the ^ carat...
How come I can't anchor it?

Last edited by yongho; 06-13-2005 at 03:32 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

correct use of "ps -ef | grep "?

I am trying to run a program which checks to see if a process is running. If the process is not running, I want to start (re-start) the process. If the process is still (already) running, do nothing. Here is the process; it starts manually: $java Validation here is my code to see if it is... (1 Reply)
Discussion started by: mulligm
1 Replies

2. Shell Programming and Scripting

Pls correct the "if" syntax

Iam a learner of UNIX. Fortunately I got this site. I want to check the file for its existance. if echo " Not present" else echo "Present" fi The above code is working fine. But I also want to check for the files which are compressed. I tried the following code and it is not... (5 Replies)
Discussion started by: ganapati
5 Replies

3. Shell Programming and Scripting

Unix shell script (grep -A 6 -B 2 "ORA-" filename

BACKGROUND: I am using Solaris 10. Some of my boxes have gnu grep and I can use -A and -B flags on those. However, the solaris flavor of grep won't use the flags -A or -B. And some of my boxes won't be getting gnu grep. Should I try using perl, awk, or sed? Actual PROBLEM: I am... (7 Replies)
Discussion started by: el_guero
7 Replies

4. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

5. Shell Programming and Scripting

What's the correct syntax to use "if-else"

hi, i'm a beginner in Linux, actually i use andLinux, i have a data file with 11 columns 170 N SER T 25 56.962 42.701 -133.423 1.00 87.04 N 171 CA SER T 25 57.076 41.790 -132.280 1.00 86.65 C 172 C SER T 25 57.766 40.492 -132.692 1.00 87.52 C 173 O SER T 25 58.653 39.988 -131.992 1.00 86.59... (6 Replies)
Discussion started by: elsa
6 Replies

6. Shell Programming and Scripting

Need Correct syntax for "if" in UNIX

I am trying to write a simple if statement but that driving me crazy:eek: with syntactical erorrs. This is what I managed to come up #!/bin/ksh USERNAME=`whoami` if ;then echo " you have logged in as report user" elif ; then echo " you have logged in as extract user" else " I dont... (3 Replies)
Discussion started by: kkb
3 Replies

7. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

8. UNIX for Dummies Questions & Answers

"tail -n 1 filename" error while "head -n 1 filename" is ok?

Hi all, I was wondering why tail -n 2 filename produce an error when I manage to do similar command on head -n 2 filename SunOS{type8code0}: tail -n 2 filename usage: tail ] tail ] (2 Replies)
Discussion started by: type8code0
2 Replies

9. Shell Programming and Scripting

grep regex, match exact string which includes "/" anywhere on line.

I have a file that contains the 2 following lines (from /proc/mounts) /dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0 /dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0 I need to match the string in the second column exactly so that only one result is returned, e.g. > grep... (2 Replies)
Discussion started by: jelloir
2 Replies

10. Shell Programming and Scripting

regex, awk, grep question "how to"

I've been working on this for 2 days and I'm not getting far. It is time to turn to you guys. With the data below, I am trying to create a file that looks like this: I'd like to use some form of egrep I think. AY#box#P04prod_to_contingency s AY#cmd#P04dump_cont_db s AY#cmd#P04get_on_ice_job s... (2 Replies)
Discussion started by: rawbi01
2 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep is used to invoke the grep on compress'ed or gzip'ed files. All options specified are passed directly to grep. If no file is speci- fied, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If zgrep is invoked as zegrep or zfgrep then egrep or fgrep is used instead of grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. For example: for sh: GREP=fgrep zgrep string files for csh: (setenv GREP fgrep; zgrep string files) AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), egrep(1), fgrep(1), zdiff(1), zmore(1), znew(1), zforce(1), gzip(1), gzexe(1) ZGREP(1)
All times are GMT -4. The time now is 11:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy