LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to find out *.sh file name in a text file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-out-%2A-sh-file-name-in-a-text-file-650522/)

mksc 06-20-2008 09:02 AM

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

pwc101 06-20-2008 09:05 AM

Code:

egrep -v "*\.sh$" inputfile > outputfile

mksc 06-20-2008 09:16 AM

Quote:

Originally Posted by pwc101 (Post 3190232)
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

pwc101 06-20-2008 10:03 AM

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 ~ $


mksc 06-23-2008 02:52 AM

hi

I did like this

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

and its working fine.

thanks & Regards
MKSC


All times are GMT -5. The time now is 05:04 AM.