What command to list files starting with "a" and ending with "v"?

0

I have an a.txt file that inside it has adsaadv I would like to look in addition to other files starting with a and ending with v.

I thought of using the grep something like, grep "^ [a-v $]" a.txt

However, I did not succeed, do I have to merge grep commands with something else?

Thank you if you can give me a clairvoyance.

    
asked by anonymous 07.04.2016 / 21:49

2 answers

3
ls | grep ^a.*v$
  • ls lists directory
  • | o pipe sends the output of ls to grep
  • grep filters the input with a regular expression, and returns on output by default
  • ^ is the beginning of the line
  • a is the character at the beginning of the line
  • .* the dot means "any character". The asterisk means "how many characters are there"
  • v is the character you want at the end
  • $ is the end of the line

As you want the extension, set to:

ls | grep ^a.*v\.txt$
  • a \ means that the next point is a point of fact, not a RegEx joker.
07.04.2016 / 23:21
1

Neither does it need to complicate so much; the old ls command can help you with this very easily.

Just make one:

ls a * v

But you have misunderstood the question, because it looks for a certain combination of text within a file, so to solve your problem, make one:

grep [^ a]. [v $] a.txt

    
07.04.2016 / 22:30