1

Here is my problem. I want to store the directory of a specific file in a variable via terminal but in my folder there are many files let say one of them is test1432.config and the other is test1432-busybox.config and the other files whose extention are not .config. So I decided to write

fst_directory="%s" %(co_directory[3:])+ "/*.config"

But If I do that in this way, it also takes the test1432-busybox.config doesnt it ? How could I do that ? thanks in advance

EDIT

The only differences between two file is the busybox part. I mean fileName-busybox.config and fileName.config. I always want to choose fileName.config

EDIT2

Since nobody share the solution. I created my own. In this case the busybox is not necessary file for me . So I decided to delete them and after that I can choose the true file easly. If the file is important and you could not delete it.You can move it somewhere else and move back after the operation.

2
  • My problem was that. There are more than one file with .config extantion and I just want to get one of them. So I do it by this way. fst_directory="%s/%s"%(co_directory[3:],fst_firmware_name)+"/*%s.config"%(fst_firmware_name) In this way, it takes only the "blablbla"fst_firmware_name.config file I hope I Could help @Braiam
    – caesar
    Aug 24, 2013 at 11:58
  • Sorry for being vague, share your solution in the answers below.
    – Braiam
    Aug 24, 2013 at 12:45

1 Answer 1

2

Assuming you have two files, one you want to list/use and one you want to ignore with the one to ignore containing - in it's filename as in -busybox:

 ls *.config | grep -v '-'

From man page about grep -v option:

      -v, --invert-match
          Invert  the  sense  of matching, to select non-matching lines.  (-v is specified by
          POSIX.)

Which basically means list all files ending with .config, pipe to grep and exclude those containing -

Or something that gives more control over the selection:

 ls | grep ".*[^-busybox].config"

Which means:

List all files in directory pipe them to grep and using a regular expression filter them to include * for everything but not those in brackets [^-busybox], ending with .config

[^] excludes.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .