Regex for filename in grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regex for filename in grep
# 1  
Old 07-01-2013
Regex for filename in grep

I want to print the filename

keyword="XXTNL_AVSKRIV2ING"
ftype="sql'

I wan to search the keyword in all the sql files and the output shoul dbe filename:count

Code:
 
grep -iwc "$keyword" *.$ftype | grep -v ":0$"

But the output does not dispaly the filename which contains space as below.

Samlefakering v 13.6.08.sql

So i was trying to modify the command as below , but it is not working.

Code:
 
grep -iwc "$keyword"  ?+[. ]*.$ftype | grep -v ":0$"

# 2  
Old 07-01-2013
What is not working? Are you sure to present the correct files to grep? Are you sure the contain your keyword? Why don't you post meaningful error msgs?
# 3  
Old 07-01-2013
The error im getting is as below.

bash-3.00$ keyword="XXTNL_AVSKRIV2ING"
bash-3.00$ ftype="wft"
bash-3.00$ grep -iwc "$keyword" ?+[. ]*.$ftype | grep -v ":0$"
grep: can't open ?+[.
grep: can't open ]*.wft
bash-3.00$
# 4  
Old 07-01-2013
Don't forget that we are dealing with shell's pattern matching, not regex matching as used in sed, awk, etc. Why wouldn't your first code work?
Code:
ftype="sql"
keyword="XXTNL_AVSKRIV2ING"
grep -iwc "$keyword" *.$ftype
Samlefakering v 13.6.08.sql:0
Samlefakering v 23.6.08.sql:0

# 5  
Old 07-01-2013
yeah..it seems there is problem in the other part of the code where i am extarcting the basename...i will correct that..Thank you for pointing this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH Regex - get filename tags, labels and descriptions

Hi, I am trying to switch from windows to linux. I have been using Autohotkey scripts for some little things. I started writing some bash scripts for NEMO browser in linux mint and I am trying to convert some of AHK scripts but as I am not a programmer. I have a hard time with regex stuff. ... (3 Replies)
Discussion started by: Bishop
3 Replies

2. UNIX for Beginners Questions & Answers

Grep regex

Hi everyone, I'm looking for a grep command to match the following pattern from a file: <EGS>10234567<EGS> I used this following command to do this: grep -E '^<EGS>{8}<EGS>' test.txt In output I got: <EGS>10234567<EGS> Till now it work, but if I add something at the end of the line... (2 Replies)
Discussion started by: Arnaudh78
2 Replies

3. UNIX for Beginners Questions & Answers

Grep in regex

Hello guys, Here i am writing a script in bash to check for a valid URL from a file using regex This is my input file http://www.yahoo.commmmmm http://www.google.com https://www.gooogle.co www.test6.co.in www.gmail.com www.google.co htt://www.money.com http://eeeess.google.com... (2 Replies)
Discussion started by: Meeran Rizvi
2 Replies

4. Shell Programming and Scripting

Diff between grep .* file name and grep '.*' filename

Hi, Can anyone let me know what is difference between grep .* foo.c grep '.*' foo.c I am not able to understand what is exact difference. Thanks in advance (2 Replies)
Discussion started by: SasDutta
2 Replies

5. Shell Programming and Scripting

grep -v and regex

How to match lines that don't contain a patern in regex it self, without using the -v option of grep? (15 Replies)
Discussion started by: vistastar
15 Replies

6. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

7. UNIX for Dummies Questions & Answers

Help with grep and regex

Hi all, I'm a beginner with linux, regex, grep, etc I am trying to get data out of a file that has about 13,000 lines in this format name - location I want to grep all the names out to one file and the locations to another so I can put them into a spreadsheet. Some have hyphenated... (14 Replies)
Discussion started by: raichlea
14 Replies

8. UNIX for Dummies Questions & Answers

grep with Regex help!

Hello everybody, I'd like to know how is it I should write a regex in unix to match a string not followed by another string (anywhere in the line). To be more specific, I want to find lines where "drop table" is found, but not followed anywhere in the line by the character "&". For... (3 Replies)
Discussion started by: mvalonso
3 Replies

9. UNIX for Dummies Questions & Answers

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. ... (2 Replies)
Discussion started by: yongho
2 Replies

10. UNIX for Dummies Questions & Answers

use of regex on grep

having a look on the regex site I saw that characters can be search using hex values http://www.regular-expressions.info/characters.html So I try to use it whith grep to find a è on a string (octal Decimal Hexa : 350 232 E8) but it doesn't work E.g. /usr/bin/echo '\0350' | egrep '\xE8' ... (0 Replies)
Discussion started by: solea
0 Replies
Login or Register to Ask a Question