If you have the whole contents of the file in a variable, then:
text = <<END
-rw-rw-r-- 1 user user 12203 Aug 6 01:02 app1.sql
-rw-rw-r-- 1 user user 12343 Aug 6 01:02 app2.sql
-rw-rw-r-- 1 user user 12238 Aug 6 01:02 app3.sql
END
files = text.scan(/\S+$/)
puts files
···
At 2009-08-06 02:31AM, "Shekar Ls" wrote:
I have the following information in a text file, which looks
like this:
-rw-rw-r-- 1 user user 12203 Aug 6 01:02 app1.sql
-rw-rw-r-- 1 user user 12343 Aug 6 01:02 app2.sql
-rw-rw-r-- 1 user user 12238 Aug 6 01:02 app3.sql
I need to Trim the unwanted strings and my output should look like this:
app1.sql
app2.sql
app3.sql
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
On Aug 6, 5:58 am, w_a_x_man <w_a_x_...@yahoo.com> wrote:
On Aug 6, 1:31 am, Shekar Ls <idealo...@hotmail.com> wrote:
> Hi guys,
> I have the following information in a text file, which looks
> like this:
> -rw-rw-r-- 1 user user 12203 Aug 6 01:02 app1.sql
> -rw-rw-r-- 1 user user 12343 Aug 6 01:02 app2.sql
> -rw-rw-r-- 1 user user 12238 Aug 6 01:02 app3.sql
> I need to Trim the unwanted strings and my output should look like this:
> app1.sql
> app2.sql
> app3.sql
> I am not good at string functions...let me know if anyone can help me
> out!!
Am Donnerstag, 06. Aug 2009, 22:20:10 +0900 schrieb Rüdiger Bahns:
Bertram Scharpf schrieb:
> As the file size will vary in width and the file names could
contain spaces this will be a little bit safer:
l = "-rw-rw-r-- 1 user user 12238 Aug 6 01:02 app3.sql"
filename = (l.split nil, 6).last[ 13..-1]
Bertram
Why not just
filename = (l.split nil, 9)[-1]
?
Because it is still allowed that filenames contain spaces (and
even other whitespaces what will fail with ls). Especially on
Samba mounts you have to expect that users heavily make use of it.