how to grep files with $ sign in their name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to grep files with $ sign in their name
# 1  
Old 05-21-2009
Java how to grep files with $ sign in their name

Hi All,

I am trying to update files placed in a folder to another directory structure, where that file pre existed. There are n directories so i have to search in every directory and where ever file exists need to replace it.

Problem faced:
1)Directories have files with name as xyz.class and abc$xyz.class (this is naming convention in java for inner classes). But when i simply grep xyz.class it gives me both which is not required only xyz.class is required

I want to know is there any command or way which treats these file names as complete one string name.
command use now : jar -tvf old_jarfiles/$jarname | grep "\<$fntoreplace\>"
# 2  
Old 05-21-2009
Try this with grep:

Code:
grep -w '^xyz.class'

Check the man page for the used option.
# 3  
Old 05-21-2009
Code:
fntoreplace="xyz.class"
 jar -tvf old_jarfiles/$jarname | grep "^$fntoreplace"

# 4  
Old 05-22-2009
Thanks for reply!!! I got to solve his by

jar -tvf sc.jar | grep "\<AudioTrack.class\>"

but my concern is to know how to grep files with $ sign
e.g
jar -tvf sc.jar | grep "\<ShutdownController$ShutdownHandler.class\>"

in real time it will be
jar -tvf sc.jar | grep "\<$fntoreplace>" [where fntoreplace contains $ sign in their name]
# 5  
Old 05-22-2009
You first question ask about to find the target file in the n directotries.
That can due with "find" and "sed" on unix command.

But the second statement show that you use grep from the list inside the jar file. So the solution is find the target from the list from the jar,isn't it?

If I am correct it means you want to find the path reference of the target class file AudioTrack.class, ShutdownController$ShutdownHandler.class
that listed in the jar file.

I also assume that you know all you target class file names.

Please try this.

1. create a a_class_file file content the list of .class file name that you want to find from the jar file.

2. You will then create a script file. For example jar_file.sh consist of command as belowing:
#!/bin.sh
for i_class in `cat a_class_file`
do
jar -tvf sc.jar | grep "\<$i_class\>"
done

Run the script jar_file.sh to get the result.
$ sh ./jar_file.sh

Hope this can help

Last edited by tom_cmu; 05-22-2009 at 07:57 AM..
# 6  
Old 05-22-2009
Yeah you are right tom_cmu. I am using the same thing in my script.

Pls. find more insight on problem :
Suppose i have two jars
Jar1 contains xyz.class , xyz$abc.class, aaa.class
Jar2 contains abc.class bbb$xyz.class, bbb.class and so on.

Queries are ---

1) At runtime if i search for abc.class in jar1 it returns true, because of xyz$abc.class which is incorrect.
It should return true only for jar2 which has file with name abc.class

2) If i have to search for file xyz$abc.class in jar1 how to do that with grep. As grep takes $ as special symbol and i cannot put \ in front of $ to suppress it in variable which contains its name.

Is there way in awk or sed to implement this

Hope I am more clear in stating problem this time. Your reply will be helpfull

snippet of script made is .....

for file in new_files/*.class
do
if [ -f $file ]
then
fntoreplace=`echo $file | cut -d "/" -f2`
echo $fntoreplace
jar -tvf old_jarfiles/$jarname | grep "\<$fntoreplace\>"

- - - - - -
# 7  
Old 05-22-2009
I guess the text that come out from jar -tvf looks like these.
<abc.class> , <xyz$abc.class>
if so why don't you try this:

jar -tvf old_jarfiles/$jarname | grep "^<$fntoreplace"

If I do a wrong guess. There is the way to put "\" in front of "$" before the text feed through the grep command as:

jar -tvf old_jarfiles/$jarname | sed 's/\$/\\$/' | grep "\<$fntoreplace\>"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable has value with = or == sign

I have a script which is reading value from property file and doing replacement in source location which contains multiple files. property file has values abc=xyz; yux=1;version=3.0; bcd=123;apple==mango when my script does search and reads value from property file. its replacing value... (1 Reply)
Discussion started by: Shamkamde
1 Replies

2. Shell Programming and Scripting

Python - glob () - How to grep same files with different extension files

Hi I Have a directory and i have some files below abc.txt abc.gif gtee.txt ghod.pid umni.log unmi.tar How can use glob function to grep abc files , i have created a variable "text" and i assigned value as "abc", please suggest me how can we use glob.glob( ) to get the output as below... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

3. Forum Support Area for Unregistered Users & Account Problems

Sign in issues

I tried logging in under my username (Michael Mullig) but as it's been a while I've forgotten my password. None of my email addresses are recognized either. Thinking that my username my have been purged due to lack of activity (understandable) I tried to re-register, only to find the name is still... (2 Replies)
Discussion started by: Mike Mullig
2 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Unable to sign in

I am unable to sign in to the UNIX forum. I tried my username "timotei2" and the password - but access was denied. My email address - <removed> - was not recognised, either. This is strange as I registered some years back. Should I re-register, or can nyou re-set my log in credentials? (1 Reply)
Discussion started by: Unregistered
1 Replies

5. Shell Programming and Scripting

Using grep $ sign help?

hi so I was debugging some scripts and I ran into a problem that did not come up before grep -n "$variable"$ ./file.txt I figured the second $ is meant to reference the end of the line but this gave me trouble in my c shell. anyone know whats wrong here or how to rewrite this??? Thank... (2 Replies)
Discussion started by: vas28r13
2 Replies

6. Shell Programming and Scripting

grep for certain files using a file as input to grep and then move

Hi All, I need to grep few files which has words like the below in the file name , which i want to put it in a file and and grep for the files which contain these names and move it to a new directory , full file name -C20091210.1000-20091210.1100_SMGBSC3:1000... (2 Replies)
Discussion started by: anita07
2 Replies

7. UNIX for Dummies Questions & Answers

@ sign in permissions?

I am using Mac OS X version 10.5.7, and had a problem accessing a folder on our shared area network. I logged in via terminal (bash shell), and did a ls -l on the main directory, and the directory that isn't showing up has an @ sign at the end: rwxr-xr-x@ 19 admin staff 2048 Jun 1 07:53... (1 Reply)
Discussion started by: aaronstella
1 Replies

8. Shell Programming and Scripting

how to grep word from .gz files & .z files

Hi I have find some account numbers from .gz files. There thousands of .gz files, also i am unable to grep .gz / .z files. I want to find file names & and those lines from list. Could you pls tell me / give me any syntax for finding word from ,gz files using grep? Thanks in advance (8 Replies)
Discussion started by: udaya_subbu
8 Replies

9. UNIX for Dummies Questions & Answers

minus sign

why a minus sign is put for options in unix commands suggestions plz (2 Replies)
Discussion started by: trichyselva
2 Replies

10. Shell Programming and Scripting

Sign on/Sign off logging script

I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem. I need... (1 Reply)
Discussion started by: Glider
1 Replies
Login or Register to Ask a Question