Help required in grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required in grep command
# 1  
Old 02-04-2004
Help required in grep command

Hi all,

I need some help in grep command in a ksh script. Actually, i need to list all files having the file name like "BORD*.DAT" but exclude the files (from the list) having name like "BORD*mgt*.DAT". For that i used the following command:

ls | grep "BORD*.DAT" | grep -v "BORD*mgt*.DAT"

but this command is not returning any values !!! Can anybody please help.

Thanks all

Panzer
# 2  
Old 02-04-2004
That's because you're thinking of the asterisk in the wrong way. Smilie

The way you have it, the first grep command will find any file with zero or more D's in it, including BOR.DAT, BORD.DAT and BORDDDDD.DAT.

So the second grep command most likely doesn't even have any files to act upon; if it did, it wouldn't behave as you expect either.

---------------
You need something like:

ls | grep "BORD.*.DAT" | grep -v "BORD.*mgt.*.DAT"

In this, the first grep command finds any file with zero or more characters between BORD and .DAT, including BORD.DAT, BORD1.DAT and BORD4321.DAT and displays those.
# 3  
Old 02-04-2004
Hi Panzer

Try this using egrep (grep with extended regular expressions):

ls BORD*.DAT | egrep -v '^BORD.*mgt.*\.DAT$'

Cheers
Helen
# 4  
Old 02-04-2004
my brain isnt working right now and i cant get the negated charicter class to agree with me. so you have to use the -v option in egrep.

ls | egrep -v BORD.+(mgt).+DAT
# 5  
Old 02-04-2004
Bug Thanks

Thanks a lot to all for helping me out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/awk : to grep only required pattern disk

Hi Experts, Need help with the following: Desired output: Only want to get the output marked in green. The file: --- Physical volumes --- PV Name /dev/disk/disk4704 PV Status available Total PE 6399 Free PE ... (3 Replies)
Discussion started by: rveri
3 Replies

2. Shell Programming and Scripting

How to grep the required part from the string?

Hi All, I am trying to fetch the particular content from the result of grep command. I am using ps-ef |grep engine| awk '{print $6}' above statement giving me /opt/test/user/domain/CORPTEST/application/CacheScheduler/CacheScheduler-CacheScheduler but I want (13 Replies)
Discussion started by: sharsour
13 Replies

3. Shell Programming and Scripting

Required Command in awk command

Hi Firends, I wanted to extract the first record of the file which starst with character say "X". And I tried an awk command which works when i try to execute it individually: awk 'substr($1,1,1)=="X"' inputfile.txt But when I use the same command in my script for which I am passing the... (2 Replies)
Discussion started by: Ajay Venkatesan
2 Replies

4. Shell Programming and Scripting

Script to process file from a directory and grep the required content and print

Hi All, below script reads the perticular files from the directory. Am trying to fetch status and print them in the required format. It needs to read line and search for string "Passed/Failed" and print them under correct sub header. script : BASE_DIR=/tmp/test/REPORT/CollectReport #... (16 Replies)
Discussion started by: Optimus81
16 Replies

5. Shell Programming and Scripting

Goto each directory and subdirectories and grep the required pattern

Hi All, I need your help in finding pattern from files present in different directories. I need to search for a pattern "xyz" from "*.txt" files which are present in different levels of directories as shown. example ------- dir1/subdir1/file.txt dir2/subdir2/subsubdir2/file.txt... (5 Replies)
Discussion started by: imas
5 Replies

6. Shell Programming and Scripting

Help required on grep command(Skip the first few lines from printing in the output)

Hi experts I want the proper argument to the grep command so that I need to skip the first few lines(say first 10 lines) and print all the remaining instances of the grep output. I tried to use grep -m 10 "search text" file*. But this gives the first 10 instances(lines) of the search string.... (7 Replies)
Discussion started by: ks_reddy
7 Replies

7. Shell Programming and Scripting

grep required data from two columns

hello, I have output from a command and I need to filter some info out of that. I tried awk command but I can not grep what I am looking for: Following is the output and I need to capture "disabled" for each volume from first column and report: # vol status Volume State ... (2 Replies)
Discussion started by: za_7565
2 Replies

8. Cybersecurity

Help Required: Command to find IP address and command executed of a user

Hi, I am trying to write a script which would figure out who has run which command and their IP. As i dont have any clue as to which commands would do this job, i request some gurus to help me on this. Thanks Vishwas (2 Replies)
Discussion started by: loggedout
2 Replies

9. Shell Programming and Scripting

Help Required regarding wc command

Hi guys, I want to find the number of records in a particular file and store that value in any other variable. I am trying this below command but it is not working and giving me an error "Uninary Operator Expected". say I have taken a variable name 'count' in which I have to store the no. of... (7 Replies)
Discussion started by: dtidke
7 Replies

10. UNIX for Dummies Questions & Answers

grep required pattern and next 2 or 3 lines

dear ones pl.kindly help me 1) how to print(grep) required pattern and following 2 or 3 lines. 2) grep required pattern(to print)+above 2 lines+below 2 or 3 lines.from a report file. ex: we have some report file kf askfjsk fksaj fk skf sjfksjd kff sjfkjs kf jskdjfklsd jfklsdf sdkfjsd fsd... (3 Replies)
Discussion started by: cvvsnm
3 Replies
Login or Register to Ask a Question