0

find -E .-regex '.*.java$' The output are as follows, why there are './' in the beginning? How can I remove the './' in the output?

MacBook-Pro:Code fqyuan$ find -E . -regex '.*\.java$'
output is:
./GZIPcompress.java
./SubsetsII.java
./Ugly.java
y fq
  • 25
  • 3
  • Do you need a regex? `find . -type f -name '*.java'` should find all the Java files with simple globbing. See: http://stackoverflow.com/q/2596462/1531971 –  Jan 18 '17 at 03:30
  • This Q is not about programming as defined for StackOverflow. It **may** be more appropriate on the S.E. related sites http://apple.stackexchange.com (AskDifferent) OR http://SuperUser.com . Use the `flag` link at the bottom of your Q and ask the moderator to move it there. Please don't post the same Q on 2 different sites. Please read http://stackoverflow.com/help/how-to-ask http://stackoverflow.com/help/dont-ask and http://stackoverflow.com/help/mcve before posting more Qs here. Good luck. – shellter Jan 18 '17 at 04:56

1 Answers1

0

You can use cut to select only specific part of line:

find -E . -regex '.*\.java$' | cut -c3-

cut -c3- will only select 3rd, 4th, 5th, ... characters only.

BTW, instead of using -E and -regex option, the find command can be simplified using -name option:

find . -name '*.java' | cut -c3-
falsetru
  • 357,413
  • 63
  • 732
  • 636