Brian T Hannan
Brian T Hannan

Reputation: 4015

How can I modify this regular expression to grab the filename from ls -a output?

Let's say I already have the output of an 'ls -la' command and I now want to parse out just the filenames. I have this regular expression so far that I found, but how can I modify this to account for there being whitespace in the filename itself?

Example 'ls -la' output:

-rw-r--r--   1 admin  staff  460340057 May  4 14:19 test_large_file.xml

Regular Expression I have so far:

\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)

Upvotes: 1

Views: 496

Answers (1)

Pedro Lobito
Pedro Lobito

Reputation: 99001

You can use something like:

/^.*\d\s+(.*?)$/m

https://regex101.com/r/mR4rH1/1

Upvotes: 1

Related Questions