Results 1 to 10 of 11
-rw-rw---- 1 test test 2809 Feb 11 19:05 /abc/xyz/test_sys/bin/sys.d/ tc1_0.sh
I want only /abc/xyz/test_sys/bin/sys.d/tc1_0.sh How can do that ???...
- 02-12-2008 #1Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
pattern searching in perl ?
-rw-rw---- 1 test test 2809 Feb 11 19:05 /abc/xyz/test_sys/bin/sys.d/tc1_0.sh
I want only /abc/xyz/test_sys/bin/sys.d/tc1_0.sh How can do that ???
- 02-12-2008 #2
Assuming none of your file names contain spaces, do this:
Otherwise, you can go a bit more complex:Code:$string=~s/^.* //;
Hope this helps.Code:$string=~s/^.*?\:\d\d //;
--
Bill
Old age and treachery will overcome youth and skill.
- 02-12-2008 #3Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
its working fine for all except for below mentioned line it does not work
-rw-rw---- 1 test test 1246 Feb 6 19:05 /abc/xyz/pt_100.sh
Can you suggest me some doc for patten searching.
thanks
- 02-12-2008 #4It worked for me. What happens when you run this script? (You may have to change the first line if Perl on your system is elsewhere.)its working fine for all except for below mentioned line it does not work
-rw-rw---- 1 test test 1246 Feb 6 19:05 /abc/xyz/pt_100.sh
When I run it, I get as outputCode:#!/usr/bin/perl $string1=<DATA>; chomp($string1); $string2=$string1; $string1=~s/^.* //; $string2=~s/^.*?\:\d\d //; print("$string1\n$string2\n"); __END__ -rw-rw---- 1 test test 1246 Feb 6 19:05 /abc/xyz/pt_100.sh
Code:/abc/xyz/pt_100.sh /abc/xyz/pt_100.sh
perlrequick - perldoc.perl.orgCan you suggest me some doc for patten searching.
perlretut - perldoc.perl.org--
Bill
Old age and treachery will overcome youth and skill.
- 02-13-2008 #5
For what it's worth, this doesn't even require a regular expression. This can be easily done with the split operator:
split produces an array, and I use the index "-1" to get the last element in that array. Note that this does not work if there is a space in the filename.Code:alex@danu ~/test/perl $ cat split_ls #!/usr/bin/perl -w # if we use split's handy implicit variable... $_ = "-rw-rw---- 1 test test 1246 Feb 6 19:05 /abc/xyz/pt_100.sh"; $name = (split)[-1]; print "$name\n"; # otherwise... $line = "-rw-rw---- 1 test test 1246 Feb 6 19:05 /abc/xyz/pt_100.sh"; $name = (split / /, $line)[-1]; print "$name\n"; alex@danu ~/test/perl $ ./split_ls /abc/xyz/pt_100.sh /abc/xyz/pt_100.sh
DISTRO=Arch
Registered Linux User #388732
- 02-13-2008 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:$s="-rw-rw---- 1 test test 2809 Feb 11 19:05 /abc/xyz/test_sys/bin/sys.d/tc1_0.sh"; print substr($s,index($s,"/"));
- 02-13-2008 #7
- 02-13-2008 #8Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
Great help, thanks all
- 03-26-2008 #9Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
is there any way to get the data between two words e.g.
REV: THIS IS LIux~#X VERSION: 4.0
not I just want "THIS IS LIux~#X"
and "4.0"
separately.Switched to Scripting
- 03-26-2008 #10Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
s there any way to get the data between two words e.g.
REV: THIS IS LIux~#X VERSION: 4.0
not I just want "THIS IS LIux~#X"
and "4.0"Switched to Scripting


Reply With Quote
