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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ls with optional char

Status
Not open for further replies.

jriggs420

Programmer
Sep 30, 2005
116
US
Hi all,

This works
Code:
ls joe/home/*"$*"
fine as a shell script. But how can I tell the shell to also return files which are optionally followed by a single letter, 'x' for example. I think using another wildcard will make this regex too greedy, TIA

Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius
 
How about...
Code:
ls joe/home/*"$*" joe/home/*x
If that doesn't do it, you might need to better define what you're looking for.
 
My guess:
ls joe/home/*"$*" joe/home/*"$*"x 2>/dev/null

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the tips guys, that's pretty close to what I was getting at, but not quite it. Maybe a little more info would help clarify what I'm really after.
suppose the directory in question has these files:
111 111x 111xx 111pp 111qqq. How can I list only the files
111 111x. Basically, I want the file with '111' and any file(s) which is optionally followed by a single 'x' (or really any character). Incidently I'm in csh, if that matters, thanks again, Joe

Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius
 
ls $1 ${1}x 2>/dev/null

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How about this...
Code:
#/bin/ksh

for FX in *[!x]x
do
    F=${FX%x}
    [[ -f $F ]] && ls $F
    ls $FX
done
This only lists files with a single "x" at the end and it's non-x-ending counterpart. It would list [tt]111[/tt] and [tt]111x[/tt].
 
Sam, I thought that 111 was the value of $1 ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top