Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression and "ls"

Status
Not open for further replies.

job357

Technical User
Sep 16, 2002
106
US
Hi,

I have a directory that has file names, "63.html?1024007406" that i would like to remove. I used ls -l '1[0-9].*' to list these file but was unsuccessful. Can someone lead me in the right direction here?

Travis
 
what about piping the output of ls through grep?

ls -l | grep '[0-9].*'

 
umm ... howabout:

Code:
ls | grep '?1[0-9]'

if you were planning on moving these files to names without ?'s you could use foreach and nawk/gawk:

Code:
foreach file (*?1[0-9]*)
echo $file | nawk 'sys=sprintf("mv \"%s\" \"%s\"\n",$0,substr($0,0,index($0,"?")-1)); system(sys);}'
end

if you have 'awk' but not gawk or nawk, use 'print' instead of system, cat it to a file, and run the file (or back tick the command) :)
 
Jad,

This is definitely a good one to know, thanks, as I often have needs of moving files; after identifiying them.

Travis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top