简体   繁体   中英

linux command line :file names that contain a number & replace string

so i am new to linux and I was wondering how do i do the following

1-list all names of file that contain a number [I know

  $ls *[0-9]*  

but it wont work if i have a file that starts with a number

2-Also replace any "an" in file names in the output with "xx" print on screen and store it in a file

I reached

ls | tr -u  "an" xx >modified.txt

problem is that it changes a to x and n to x ...but i want an together not separately

Thanks

List all names of file that contain a number Your example works fine for me for files that start with a number, so you might want to clarify what sort of Linux system you're on, or which shell or language you're using.

# In sh/bash:
ls *[0-9]*
# with perl:
perl -e '@globbed_files = <*[0-9]*>; print "@globbed_files\n"'
# With find (filters out directories):
find -maxdepth 1 -name '*[0-9]*' -type f

Replace any "an" in file names in the output with "xx" print on screen and store it in a file

ls | sed 's/an/xx/g' | tee file.out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM