grep for a particular entry in the file name
Dear all,
I have a folder with following list of files with names like amg-9876544-M37421-3000282.PDF amg-9876544-M37408-3000457.PDF amg-9876544-M37488-3000260.PDF amg-9876544-M37481-3300063.PDF amg-9876544-M37454-3000675.PDF amg-9876544-M37543-3000672.PDF amg-9876544-M37541-3363000.PDF amg-9876544-M37528-3000381.PDF amg-9876544-M37524-3000432.PDF amg-9876544-M37506-3000352.PDF amg-9876544-M37500-3021100.PDF amg-9876544-M37585-3850050.PDF amg-9876544-M37577-3005105.PDF amg-9876544-M37565-3000502.PDF amg-9876544-M37611-3300527.PDF amg-9876544-M37610-3300150.PDF amg-9876544-M37607-3300259.PDF I want to list all the files that has the entry with 33..for ex..file with name amg-9876544-M37607-3300259.PDF after the -. If I give ls -rlt | grep *33* it lists all the file with entry 33 anywhere in it.I want to grep for files with 33 after that "-" in the file name.. Please suggest Kai |
If the file names have the same number of characters and digits, as in your example, you can simply use the ? wildcard to match any single character:
Code:
ls -lrt amg-???????-??????-33?????.PDF |
Put a period in front of the '-'. So it looks like:
Code:
ls -rlt | grep .-33 |
Put a . in front of the dash.
ls -rlt | grep .-33 |
Quote:
ls -lrt | grep amg-????????-????????-33??????.PDF doesn't display anything.. am sure that I replaced all the places with q marks Please advise Kai |
You don't have to use grep for this
Quote:
|
Quote:
Thanks Rabbit2345, but it doesn't help ls -lr | grep *.-33* (or) ls -lr | grep .-33 doesn't display anything. Please advise Kai |
Quote:
Code:
$ ls -l |
Thanks a lot Colucix, it works fine..
Can you also tell me how can I move this conditioned files to another folder in the same file system Thanks Kai |
Quote:
Code:
$ mv amg-???????-??????-33?????.PDF /path/to/destination/dir Code:
mv amg-9876544-M37481-3300063.PDF amg-9876544-M37541-3363000.PDF amg-9876544-M37607-3300259.PDF amg-9876544-M37610-3300150.PDF amg-9876544-M37611-3300527.PDF /path/to/destination/dir |
All times are GMT -5. The time now is 12:31 PM. |