02-20-2011
Hi Scrutinizer, rdcwayx
Thanks for the input guys..:-) I really appreciate it
Scrutinizer
I think the way you hacked through the string pattern was awesome...
My only question is the use of case ie the variable $4 is actually the superset of $i so Im not sure how the case $4 check actually works...it does...i tried it but isnt it like checking if a superset is present in its subset? how does that work?
eg $4 = "string1_string2_string3_string4_string5_string6_string7"
and the value of i that is the file names after the parsing are eg
$i = "string1_string2"
or $i= "string3_string4" etc...so how does the case of $4 work ?
Thanks for the solution..It works....Im just trying to understand this
rdcwayx
The solution works for the example you gave but doesnt work for the other cases....Thanks a lot though :-)
You guys are great....
I hope I can help some one like this someday.
Ruk
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I was writing a shell script for FTPing files for a machine. now i am facing a problem in it. The problem is i want to ftp files which do not end with a particular pattern. The pattern is file should not end with .dd ( d=digit )
for eg: say i have files
file
file.01
file.02
... (0 Replies)
Discussion started by: dipendra_g
0 Replies
2. Shell Programming and Scripting
Hi,
I'm wondering what is the best way to parse out a long string that has a specific deliminator and outputting each token between the delim on a newline?
i.e. input
text1,text2,text3,tex4
i.e. output
text1
text2
text3
text4 (8 Replies)
Discussion started by: primp
8 Replies
3. Shell Programming and Scripting
Hey guys,
I have this file generated by me... i want to create some HTML output from it.
The problem is that i am really confused about how do I go about reading the file.
The file is in the following format:
TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies
4. Shell Programming and Scripting
Alright,
I'm new to Perl so be gentle. Given the following script:
----
open(file, "<file.txt");
@lines = <file>;
close(file);
$var = print $lines;
----
So I'm printing line 18 of the file "file.txt". I now want the 5th column, minus the forward slash. The line looks like this:
... (2 Replies)
Discussion started by: wxornot
2 Replies
5. Shell Programming and Scripting
Quick question...I'm trying to grab the .tif file name from this output from our fax server. What is the best way i can do this in a bash script? I have been looking at regular expressions with bash or using awk but having some trouble. thanks! The only output i want is... (5 Replies)
Discussion started by: kuliksco
5 Replies
6. UNIX for Dummies Questions & Answers
This should be somewhat simple, but I need some help with this one.
I have a bunch of files with tags on the end like so...
Filename {tag1}.ext
Filename2 {tag1} {tag2}.ext
I want to hold in a variable just the filename with all the " {tag}" removed. The tag can be anything so I'm looking... (4 Replies)
Discussion started by: kerppz
4 Replies
7. Shell Programming and Scripting
Hi all!
Looking for some help parsing filenames in bash. I have a directory full of files named "livingroom-110111105637.avi". The format is always date and time (yymmddhhmmss). I'm looking to parse the filenames so they are a little more easily readable. Maybe rename them to... (4 Replies)
Discussion started by: mtehonica
4 Replies
8. Shell Programming and Scripting
Hi all :)
It sounds complex, for example
I want to find the whole html file (there are 5 entries of this string and I need to get all of them) for the string
"<td class="contentheading" width="100%">", get the next line from it only till the point that says "</td>", plus removing \t (tabs)
... (6 Replies)
Discussion started by: hakermania
6 Replies
9. Shell Programming and Scripting
Hi,
I have a string which can be completely unstructred. I am looking to parse out values within that String.
Here is an example
<Random Strings> String1=<some number a> String2=<some number b> String3=<some number c> Satish=<some number d> String4=<some number e>
I only want to parse out... (1 Reply)
Discussion started by: satishrao
1 Replies
10. Shell Programming and Scripting
I have a text file like this , where the same set of three lines repeat with different values.
INFO: processing now 03/25/2015-00:06:05 03/25/2015-00:16:04
------Invoking myexe table=table1
INFO 25-03 00:20:26,801 - Finished processing (I=0, O=57, R=57, W=57, U=0, E=0)
INFO: processing... (4 Replies)
Discussion started by: Lakshmikumari
4 Replies
LEARN ABOUT CENTOS
encode::guess
Encode::Guess(3) User Contributed Perl Documentation Encode::Guess(3)
NAME
Encode::Guess -- Guesses encoding from data
SYNOPSIS
# if you are sure $data won't contain anything bogus
use Encode;
use Encode::Guess qw/euc-jp shiftjis 7bit-jis/;
my $utf8 = decode("Guess", $data);
my $data = encode("Guess", $utf8); # this doesn't work!
# more elaborate way
use Encode::Guess;
my $enc = guess_encoding($data, qw/euc-jp shiftjis 7bit-jis/);
ref($enc) or die "Can't guess: $enc"; # trap error this way
$utf8 = $enc->decode($data);
# or
$utf8 = decode($enc->name, $data)
ABSTRACT
Encode::Guess enables you to guess in what encoding a given data is encoded, or at least tries to.
DESCRIPTION
By default, it checks only ascii, utf8 and UTF-16/32 with BOM.
use Encode::Guess; # ascii/utf8/BOMed UTF
To use it more practically, you have to give the names of encodings to check (suspects as follows). The name of suspects can either be
canonical names or aliases.
CAVEAT: Unlike UTF-(16|32), BOM in utf8 is NOT AUTOMATICALLY STRIPPED.
# tries all major Japanese Encodings as well
use Encode::Guess qw/euc-jp shiftjis 7bit-jis/;
If the $Encode::Guess::NoUTFAutoGuess variable is set to a true value, no heuristics will be applied to UTF8/16/32, and the result will be
limited to the suspects and "ascii".
Encode::Guess->set_suspects
You can also change the internal suspects list via "set_suspects" method.
use Encode::Guess;
Encode::Guess->set_suspects(qw/euc-jp shiftjis 7bit-jis/);
Encode::Guess->add_suspects
Or you can use "add_suspects" method. The difference is that "set_suspects" flushes the current suspects list while "add_suspects"
adds.
use Encode::Guess;
Encode::Guess->add_suspects(qw/euc-jp shiftjis 7bit-jis/);
# now the suspects are euc-jp,shiftjis,7bit-jis, AND
# euc-kr,euc-cn, and big5-eten
Encode::Guess->add_suspects(qw/euc-kr euc-cn big5-eten/);
Encode::decode("Guess" ...)
When you are content with suspects list, you can now
my $utf8 = Encode::decode("Guess", $data);
Encode::Guess->guess($data)
But it will croak if:
o Two or more suspects remain
o No suspects left
So you should instead try this;
my $decoder = Encode::Guess->guess($data);
On success, $decoder is an object that is documented in Encode::Encoding. So you can now do this;
my $utf8 = $decoder->decode($data);
On failure, $decoder now contains an error message so the whole thing would be as follows;
my $decoder = Encode::Guess->guess($data);
die $decoder unless ref($decoder);
my $utf8 = $decoder->decode($data);
guess_encoding($data, [, list of suspects])
You can also try "guess_encoding" function which is exported by default. It takes $data to check and it also takes the list of
suspects by option. The optional suspect list is not reflected to the internal suspects list.
my $decoder = guess_encoding($data, qw/euc-jp euc-kr euc-cn/);
die $decoder unless ref($decoder);
my $utf8 = $decoder->decode($data);
# check only ascii, utf8 and UTF-(16|32) with BOM
my $decoder = guess_encoding($data);
CAVEATS
o Because of the algorithm used, ISO-8859 series and other single-byte encodings do not work well unless either one of ISO-8859 is the
only one suspect (besides ascii and utf8).
use Encode::Guess;
# perhaps ok
my $decoder = guess_encoding($data, 'latin1');
# definitely NOT ok
my $decoder = guess_encoding($data, qw/latin1 greek/);
The reason is that Encode::Guess guesses encoding by trial and error. It first splits $data into lines and tries to decode the line
for each suspect. It keeps it going until all but one encoding is eliminated out of suspects list. ISO-8859 series is just too
successful for most cases (because it fills almost all code points in x00-xff).
o Do not mix national standard encodings and the corresponding vendor encodings.
# a very bad idea
my $decoder
= guess_encoding($data, qw/shiftjis MacJapanese cp932/);
The reason is that vendor encoding is usually a superset of national standard so it becomes too ambiguous for most cases.
o On the other hand, mixing various national standard encodings automagically works unless $data is too short to allow for guessing.
# This is ok if $data is long enough
my $decoder =
guess_encoding($data, qw/euc-cn
euc-jp shiftjis 7bit-jis
euc-kr
big5-eten/);
o DO NOT PUT TOO MANY SUSPECTS! Don't you try something like this!
my $decoder = guess_encoding($data,
Encode->encodings(":all"));
It is, after all, just a guess. You should alway be explicit when it comes to encodings. But there are some, especially Japanese,
environment that guess-coding is a must. Use this module with care.
TO DO
Encode::Guess does not work on EBCDIC platforms.
SEE ALSO
Encode, Encode::Encoding
perl v5.16.3 2013-04-29 Encode::Guess(3)