Oneliner ---split string to character by piping shell output to perl
Hello,
I was trying to split a string to characters by perl oneliner.
But did not work as with bash script pipe:
However, I want ignore the space and case.
1) What did I miss with my perl oneliner?
2) What are the options to ignore the space and case?
3) Want perl oneliner for learning purpose for 2)
Googled for a while, but no example for my exact case. Thanks a lot!
Hi All,
I am trying to convert the below Csh code into Perl.
But i have the following error.
Can any expert help ?
Error:
ls: *tac: No such file or directory
Csh
set $ST_file = `ls -rt *$testid*st*|tail -1`;
Perl
my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
i want to split the input by a space and remove specific characters like full stop, comma...... etc. and then save each word in an array.
i got something below, but it didn't work. can anyone please help me?
Thank you
#!/usr/bin/perl -w
while (<>)
{
$line = <>;
@word = split(' ',... (6 Replies)
All I'm trying to split a string at the $ into arrays
@data:=<dataFile>
a $3.33
b $4.44
dfg $0.56
The split command I have been playing with is:
split(/\$/, @data)
which results with
a .33 b .44 dfg .56
any help with this is appreciated
/r
Rick (9 Replies)
Hi,
I have file: data.log.1
### s1
main.build.3495
main.build.199
main.build.3408
###s2
main.build.3495
main.build.3408
main.build.199
I want to read this file and store in two arrays in Perl.
I have following command, which is working fine on command prompt.
perl -n -e... (1 Reply)
I am trying to take first 3 columns in a file which matches the word "abc", but i am getting the below error,
<error>
Global symbol "@F" requires explicit package name at ./new.pl
</error>
whereas when i give the below,grep abc /home/test/file.txt|perl -lane 'print \"$F $F $F\" in unix prompt... (4 Replies)
Hi
I have a file say text.txt and has data as below.
text.txt
-------
/abc/def/tom/hanks
/abc/def/al/pacino
/def/dgg/matt/damon
Now I have to cut the field 3 and field 4 treating / as delimiter and save in the same file. Below is the how the output should be in the same file.
I... (1 Reply)
How can I split following input into stwo strings:
Input:
1^~^2^~^3^~^4^~^5^~^6^~^7^~^8^~^9
Output:
$string1 = 1^~^2^~^
$string2 = 3^~^4^~^5^~^6^~^7^~^8^~^9
Note: the length of string may vary, say upto 15. String 1 will contain only first two. string2 will contain... (10 Replies)
hi,
i am trying to write a script to generate ouput in the following format:
##### buildappi abcd_sh nodebug.#####
##### buildappi ijk_sh nodebug.#####
The given string is as follows:
xtopSharedDLLs = "abcd_sh def_sh ijk_sh " \
+ "jkl_sh any_sh... (15 Replies)
Hi All,
How to split the string KAR_Celltick_Ban_GSMGW3 and want to pickup the third filed. Sometime the string may be "KAR_Celltick_Ban" like this
Thanks in advance (1 Reply)
Hello
I have string (string can have more sections)
LINE="AA;BB;CC;DD;EE"I would like to assigne each part of string separated by ";" to some new variable.
Can someone help? (4 Replies)
Discussion started by: vikus
4 Replies
LEARN ABOUT DEBIAN
text::context::eitherside
Text::Context::EitherSide(3pm) User Contributed Perl Documentation Text::Context::EitherSide(3pm)NAME
Text::Context::EitherSide - Get n words either side of search keywords
SYNOPSIS
use Text::Context::EitherSide;
my $text = "The quick brown fox jumped over the lazy dog";
my $context = Text::Context::EitherSide->new($text);
$context->as_string("fox") # "... quick brown fox jumped over ..."
$context->as_string("fox", "jumped")
# "... quick brown fox jumped over the ..."
my $context = Text::Context::EitherSide->new($text, context => 1);
# 1 word on either side
$context->as_string("fox", "jumped", "dog");
# "... brown fox jumped over ... lazy dog",
Or, if you don't believe in all this OO rubbish:
use Text::Context::EitherSide qw(get_context);
get_context(1, $text, "fox", "jumped", "dog")
# "... brown fox jumped over ... lazy dog"
DESCRIPTION
Suppose you have a large piece of text - typically, say, a web page or a mail message. And now suppose you've done some kind of full-text
search on that text for a bunch of keywords, and you want to display the context in which you found the keywords inside the body of the
text.
A simple-minded way to do that would be just to get the two words either side of each keyword. But hey, don't be too simple minded, because
you've got to make sure that the list doesn't overlap. If you have
the quick brown fox jumped over the lazy dog
and you extract two words either side of "fox", "jumped" and "dog", you really don't want to end up with
quick brown fox jumped over brown fox jumped over the the lazy dog
so you need a small amount of smarts. This module has a small amount of smarts.
EXPORTABLE
get_context
This is primarily an object-oriented module. If you don't care about that, just import the "get_context" subroutine, and call it like so:
get_context($num_of_words, $text, @words_to_find)
and you'll get back a string with ellipses as in the synopsis. That's all that most people need to know. But if you want to do clever
stuff...
METHODS
new
my $c = Text::Context::EitherSite->new($text [, context=> $n]);
Create a new object storing some text to be searched, plus optionally some information about how many words on either side you want. (If
you don't like the default of 2.)
context
$c->context(5);
Allows you to get and set the number of the words on either side.
as_sparse_list
$c->as_sparse_list(@keywords)
Returns the keywords, plus n words on either side, as a sparse list; the original text is split into an array of words, and non-contextual
elements are replaced with "undef"s. (That's not actually how it works, but conceptually, it's the same.)
as_list
$c->as_list(@keywords)
The same as "as_sparse_list", but single or multiple "undef"s are collapsed into a single ellipsis:
(undef, "foo", undef, undef, undef, "bar")
becomes
("...", "foo", "...", "bar")
as_string
$c->as_string(@keywords)
Takes the "as_list" output above and joins them all together into a string. This is what most people want from "Text::Context::EitherSide".
EXPORT
"get_context" is available as a shortcut for
Text::Context::EitherSide->new($text, context => $n)->as_string(@words);
but needs to be explicitly imported. Nothing is exported by default.
SEE ALSO
Text::Context is an even smarter way of extracting a contextual string.
AUTHOR
Current maintainer: Tony Bowden
Original author: Simon Cozens
BUGS and QUERIES
Please direct all correspondence regarding this module to:
bug-Text-Context-EitherSide@rt.cpan.org
COPYRIGHT AND LICENSE
Copyright 2002-2005 by Kasei Limited, http://www.kasei.com/
You may use and redistribute this module under the terms of the Artistic License 2.0.
http://www.perlfoundation.org/artistic_license_2_0
perl v5.10.0 2009-05-04 Text::Context::EitherSide(3pm)