LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-15-2013, 06:56 AM   #1
Ladowny
Member
 
Registered: Oct 2006
Distribution: Debian, OpenBSD, FreeBSD
Posts: 53

Rep: Reputation: 14
grep in files contaning multiple hyphen ( dash ) in name


HI

I have log files generated by 3rd party application that are named like this

acct-2013-11-14-0000.csv.gz
acct-2013-11-14-0001.csv.gz
acct-2013-11-15-0000.csv.gz
acct-2013-11-15-0001.csv.gz
acct-2013-11-15-0002.csv.gz

I need to find lines containing a string, so when I do
Code:
$ zgrep mystring ./acct*
I get the result, bu when I try narrowing the search to a particular month like this
Code:
$ zgrep mystring ./acct-2013-11*
I get nothing

When googling the issue I found that hyphen (-) is a special character and that's where my problem comes from. I tried escaping it ( ./acct\-2013\-11* ), but no luck. Any idea how to grep in files containing hyphens ?
 
Old 11-15-2013, 07:05 AM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
try using --

Code:
zgrep -- mystring ./acct-2013-11*
 
Old 11-17-2013, 12:58 AM   #3
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by Firerat View Post
try using --

Code:
zgrep -- mystring ./acct-2013-11*
Using '--' help only when filename begin with '-', otherwise, while harmless it make no good
 
Old 11-17-2013, 03:12 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Try the following:
Code:
zgrep mystring ./acct[-]2013[-]11*
 
Old 11-17-2013, 03:49 AM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by Valery Reznic View Post
Using '--' help only when filename begin with '-', otherwise, while harmless it make no good
it _*should*_ work,

it tells zgrep ( and many other ) programs to treat - as a 'normal' char. ( stop processing -X args )

but you are right, in it is normally useful for things that start - , and makes no difference here

just tested on debian/jessie

I get no problems,

Code:
for i in {0..9};do
    echo "mystring${i}" > acct-2013-11-15-000${i}.cvs
    gzip acct-2013-11-15-000${i}.cvs
done
zgrep mystring acct-2013-11*
zgrep -- mystring acct-2013-11*
zgrep mystring -- acct-2013-11*
all 'work'


@Ladowny

what do you get from this
Code:
zgrep mystring acct-2013-11* ; echo $?
 
Old 11-18-2013, 01:01 PM   #6
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
It looks like the OP has not seen any of the answers (or hasn't seen them being logged in).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to use grep to search for words/sentences starting with hyphen? aswani Programming 12 09-01-2012 07:44 AM
[SOLVED] how do I escape dash when using grep hui Programming 13 11-18-2011 02:57 PM
removing the dash within the name of multiple files kaplan71 Linux - General 4 11-07-2011 12:58 PM
grep multiple files Curtor Linux - Newbie 10 07-06-2008 01:32 PM
Using grep to change multiple files zwyrbla Linux - General 5 01-11-2005 02:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration