LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-20-2008, 06:40 AM   #16
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30

Quote:
ls | grep -v file1.xml file2.xml file3.xml
man grep gives
Grep searches the named input FILEs (or standard input if no files are
named, or the file name - is given) for lines containing a match to
the given PATTERN.


how could grep be used in finding files(while it is used to find patterns matching lines in files.)
 
Old 07-20-2008, 06:42 AM   #17
mrrangerman
Member
 
Registered: Oct 2007
Location: MI
Distribution: Debian Slackware
Posts: 528

Rep: Reputation: 50
Code:
ls --hide=*.xml
Works for me.
 
Old 07-20-2008, 06:44 AM   #18
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
How about:

Code:
ls |grep -v .xml$
Which ensures that only the final instance of .xml in the filename is matched.
 
Old 07-20-2008, 06:45 AM   #19
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30
Quote:
ls | grep -v [.]xml$
Thanks .it works.
Quote:
I asked to be more specific about the grep question...
As the grep manual says ,grep is used to find pattern matching in files.But how do u use in finding files.

Please explain how the above command works.
 
Old 07-20-2008, 06:46 AM   #20
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by babu198649 View Post
how could grep be used in finding files(while it is used to find patterns matching lines in files.)
Ok. That's clear now. The command grep used in the above examples, should search a pattern in the list of files piped from the command ls. Actually using option -v should exclude all matching entries.

You may think at the list of files given as standard input to the grep command, as the content of a file.
 
Old 07-20-2008, 06:49 AM   #21
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by David the H. View Post
How about:

Code:
ls |grep -v .xml$
Which ensures that only the final instance of .xml in the filename is matched.
Actually this matches all the files with "xml" at the end, since the dot in a pattern has the special meaning of any single character. To literally match a dot, you should enclose it in a "character list", using square brackets.
 
Old 07-20-2008, 06:56 AM   #22
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30
Quote:
You may think at the list of files given as standard input to the grep command, as the content of a file.
Thanks.
My intrest is to solve the problem with Regular expressions(learning Regular Expressions).Can u please give a solution without using grep(ie.only using Regular Expressions,especially using carat symbol(^)).
 
Old 07-20-2008, 06:57 AM   #23
Clemente
Member
 
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
This is funny - and slightly off topic:
After reading the thread, I found that my machine does not accept any ls --hide command. Additionally, "man hide" does not mention any --hide parameter. Searching with google, I found a manpage, that describes a ls variant WITH the parameter --hide. Are there different ls's around?

To write something that matches the topic:
I see that the OP has found a solution with piping into grep, just to add another way: One can use find to find any file:

Code:
find . ! -iname "*.xml" -maxdepth 1
Does search in current directory (.)
for any file that doesn NOT (!)
contain the case insensitive (-iname)
string pattern *.xml (*.xml).
Find will descend recursively into subdirs for 1 level (-maxdepth 1).
Latter is in fact no descending, since level 1 is the starting level.
 
Old 07-20-2008, 07:07 AM   #24
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by Clemente View Post
After reading the thread, I found that my machine does not accept any ls --hide command. Additionally, "man hide" does not mention any --hide parameter. Searching with google, I found a manpage, that describes a ls variant WITH the parameter --hide. Are there different ls's around?
Sincerely I don't know, I can only tell that I have
Code:
$ ls --version
ls (GNU coreutils) 6.9
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard Stallman and David MacKenzie.
on OpenSuSE 10.3. I have not other systems at hand right now, but I will check tomorrow.
 
Old 07-20-2008, 07:09 AM   #25
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30
find . ! -iname "*.xml" -maxdepth 1

it works ,thank u

how to solve only with Regular Expressions (without -iname option).

Last edited by babu198649; 07-20-2008 at 07:19 AM.
 
Old 07-20-2008, 10:22 AM   #26
Clemente
Member
 
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
You possibly want to check "man find" for the options --regextype and --regex.

First option chooses an regex type (default is emacs style), second one feeds a regex pattern.

@colucix:
Yes, I should have thinking about newer and older versions by my own... ;-) Somehow, I took those very, very basic tools for static and unchangeable...
Back on my desktop (Ubuntu 8.04) I find --hide supported by an ls with version 6.10.
The other system, where I wrote my last posting, provided ls version 5.2.1 with no --hide support.
 
Old 07-20-2008, 04:24 PM   #27
rajwinder
LQ Newbie
 
Registered: Jun 2008
Posts: 21

Rep: Reputation: 15
find /dirname -not -name "*.xml"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to delete the lines in xml FILES ragavendran31 Linux - Newbie 1 01-19-2008 02:24 PM
flat files or xml and css? trscookie Linux - General 1 01-17-2006 10:24 AM
Splitting XML Files Lanmate Linux - Software 0 11-09-2005 05:24 PM
Saving *.doc & *.XML files on old computers Kye Mandriva 3 10-23-2004 10:28 PM
Writing XML files from C++ application Ezeeckiel Programming 1 04-19-2004 04:06 AM


All times are GMT -5. The time now is 12:06 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration