LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-20-2008, 10:02 AM   #1
mksc
LQ Newbie
 
Registered: May 2008
Posts: 10

Rep: Reputation: 0
Exclamation how to find out *.sh file name in a text file


hi all
I have a text file which contains name of files, I want to remove *.sh files from that list.
what is solution ?


thanks
MKSC
 
Old 06-20-2008, 10:05 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Code:
egrep -v "*\.sh$" inputfile > outputfile

Last edited by pwc101; 06-20-2008 at 10:07 AM. Reason: improved regexp
 
Old 06-20-2008, 10:16 AM   #3
mksc
LQ Newbie
 
Registered: May 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Question

Quote:
Originally Posted by pwc101 View Post
Code:
egrep -v "*\.sh$" inputfile > outputfile
hi

its not working.

I explain you my problem. let i have a file
abc.txt it contains
hjhj.sh
jhdj.txt
skf.pdf
jks.dat
jk.shd
vsh.txt
sh.ro

I want to create another file which contains
jhdj.txt
skf.pdf
jks.dat
jk.shd
vsh.txt
sh.ro

Now what is solution of this?

Thanks
MKSC
 
Old 06-20-2008, 11:03 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
It works for me:
Code:
pwc101@example_win ~ $ cat abc.txt
hjhj.sh
jhdj.txt
skf.pdf
jks.dat
jk.shd
vsh.txt
sh.ro
pwc101@example_win ~ $ egrep -v "*\.sh$" abc.txt
jhdj.txt
skf.pdf
jks.dat
jk.shd
vsh.txt
sh.ro
pwc101@example_win ~ $
Try
Code:
grep -v -E "*\.sh$" abc.txt > def.txt
instead.

grep -E and egrep are synonymous.

I tested this on RedHat:
Code:
pwc101@example ~$ grep --version; echo; cat /etc/redhat-release; echo; bash --version
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Red Hat Enterprise Linux WS release 4 (Nahant Update 5)

GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.
pwc101@example ~$
and Cygwin:
Code:
pwc101@example_win ~ $ grep --version; echo; bash --version
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


GNU bash, version 3.2.39(19)-release (i686-pc-cygwin)
Copyright (C) 2007 Free Software Foundation, Inc.
pwc101@example_win ~ $

Last edited by pwc101; 06-20-2008 at 11:07 AM. Reason: added transcript of me running it
 
Old 06-23-2008, 03:52 AM   #5
mksc
LQ Newbie
 
Registered: May 2008
Posts: 10

Original Poster
Rep: Reputation: 0
hi

I did like this

cat "$filePath" | grep "\b.sh\b"

and its working fine.

thanks & Regards
MKSC
 
  


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
Find and replace text in multiple file Bad_Bob Linux - Software 9 05-08-2008 03:31 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 03:36 PM
Code to find out text file size Deepak Inbasekaran Programming 10 04-11-2006 05:52 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 08:15 PM
Command to find file with text chamanrana Linux - Software 10 12-02-2004 11:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:17 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