What is the list command for files starting with "a" and ending with "v"?

Asked

Viewed 1,390 times

0

I have a.txt file that inside it has adsaadv I would like to search beyond it other files started by and finished by v.

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

However, I was unsuccessful, I have to merge grep commands with something more ?

I’d appreciate it if you could give me a little clarity.

  • a regex ^a(.*)v$ gives the expected result?

  • http://meta.pt.stackoverflow.com/a/1079

2 answers

3


ls | grep ^a.*v$
  • ls list the directory
  • | the pipe sends out the ls to the grep
  • grep filter input with a regular expression, and return to output by default
  • ^ is the beginning of the line
  • a is the character right at the beginning of the line
  • .* dot means "any character". The asterisk means "how many characters are"
  • v is the character you want at the end
  • $ is the end of the line

How do you want the extension, adjust to:

ls | grep ^a.*v\.txt$
  • to \ means that the next point is a point of fact, not a joker of Regex.
  • Now it was perfectly, thank you for the reply.

  • possibly with plicas: ...grep 'a.*v\.txt$'

  • 1

    @Jjoao when it has certain characters in the middle even needs (spaces, for example)

1

nor need to complicate so much; the old command ls can help you in this already very easily.

Just make a:

ls a*v

But you expressed yourself badly in the question, because you are looking for a certain combination of text within a file, so to solve your problem, do a:

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

  • is a*v ne.txt ? Deu command not found or uses it next to grep ?

  • Thanks ai, now it worked, however in the return, selected in red only the V, my doubt was really how to make two distinct searches I was trying with [ a-v$]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.