Sponsored Content
Full Discussion: Perl parsing help required.
Top Forums UNIX for Advanced & Expert Users Perl parsing help required. Post 302595693 by suverman on Saturday 4th of February 2012 08:14:54 AM
Old 02-04-2012
Perl parsing help required.

Hello, I got a file like this.


5201
5202
5203
5204
1234
2345
3456
4567
6210
6220
6230
6240


The required output should be

5201 1234 6210
5202 2345 6220
5203 3456 6230
5204 4567 6240


I have huge files where patterns repeat in the same column,
like first x numbers of items would be column1, next x numbers be
column 2 etc. X varies with different files. Can I get an example code.

Thanks a ton.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl help required

hi previously this program used to ask for user input to perform operation so i have done the modifications but problem is that i have to create new file and redirect that file as input to this file and i want to avoid that so i made following modifications in program and i am not sure if its... (1 Reply)
Discussion started by: zedex
1 Replies

2. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

3. Shell Programming and Scripting

Perl Script required...

Hi All, Windows Platform. Perl Scripting. I have a file called 'hostnames.txt' contains hostname entries one by one line. Script has to perform the following command for each entry in that file. ovtopofix -G <hostname> Please anybody give me the script on this requirement. Thanks,... (1 Reply)
Discussion started by: ntgobinath
1 Replies

4. UNIX for Advanced & Expert Users

Perl - Help required

I am trying to upload a file to a SQL database table. The column type is IMAGE. I am looking for a solution to upload a word doc file. I tried 3 approaches. 1) my $fileToStore = "mytest.doc"; open IPFILE, "<", $name; binmode IPFILE; while (<IPFILE>) { $fileToStore .= $_; } close IPFILE;... (1 Reply)
Discussion started by: b.paramanatti
1 Replies

5. Shell Programming and Scripting

perl required output

Hi, I have a string in log file from that i need to pick the username. the string is like this-- pid 2172 tid 3124: 160: 10110847: userName : pid 2172 tid 3124: 160: 10110847: userName : pid 2172 tid 3124: 160: 10110847: userName : pid 2172 tid 3124: 160: 10110847: userName : pid... (5 Replies)
Discussion started by: namishtiwari
5 Replies

6. Shell Programming and Scripting

Parsing information in perl

So i'm trying to write a perl script that logins into a network switch via ssh: #sh ip traffic IP statistics: Rcvd: 1460119147 total, 563943377 local destination 0 format errors, 0 checksum errors, 48401998 bad hop count 0 unknown protocol, 8379279 not a gateway ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

7. Shell Programming and Scripting

Help required in parsing a csv file

Hi Members, I am stuck with the following problem. Request your kind help I have an csv file which contains, 1 header record, data records and 1 footer record. Sample is as below Contents of cm_update_file_101010.csv -------------------------------------------------- ... (6 Replies)
Discussion started by: ramakanth_burra
6 Replies

8. Shell Programming and Scripting

PERL: Help required exact match

Hello, My requirement is to iterate over all the lines of a file and compare them with a word and perform some operations if exact match is found. For the snippet below, it works even if contents of line include "diff" and "diff:". I want it to work only if it is exactly "diff" and is not... (2 Replies)
Discussion started by: sarbjit
2 Replies

9. Shell Programming and Scripting

Perl script required for processing the data

I have following result.log file (always has 2 lines) which I need to process, cat result.log name.cmd.method,"result","abc","xyz"; name="hello,mine.12345,"&"tree"&" xyz "&" tree "&" xyz", data="way,"&" 1"&"rate-me"&"1"&"rate-me",str="",ret=""; now I need to extract the strings/data as... (4 Replies)
Discussion started by: perlDiva
4 Replies

10. Shell Programming and Scripting

Xsltproc showing error in parsing xml...help required

I need to parse text between xml tags using xsltproc. It seems the easiest way. Here the Input file looks like <?xml version="1.0" ?> - <tag:ROOT xmlns:as="http://some.org/some.xsd" xmlns:tag="http://www.tag.org/schemas" xmlns:xs="http://some.org/"> - <tag:L1> - <tag:L2> - <tag:L3> ... (2 Replies)
Discussion started by: alpha_1
2 Replies
version(3pm)						 Perl Programmers Reference Guide					      version(3pm)

NAME
version - Perl extension for Version Objects SYNOPSIS
# Parsing version strings (decimal or dotted-decimal) use version 0.77; # get latest bug-fixes and API $ver = version->parse($string) # Declaring a dotted-decimal $VERSION (keep on one line!) use version; our $VERSION = version->declare("v1.2.3"); # formal use version; our $VERSION = qv("v1.2.3"); # shorthand use version; our $VERSION = qv("v1.2_3"); # alpha # Declaring an old-style decimal $VERSION (use quotes!) our $VERSION = "1.0203"; # recommended use version; our $VERSION = version->parse("1.0203"); # formal use version; our $VERSION = version->parse("1.02_03"); # alpha # Comparing mixed version styles (decimals, dotted-decimals, objects) if ( version->parse($v1) == version->parse($v2) ) { # do stuff } # Sorting mixed version styles @ordered = sort { version->parse($a) <=> version->parse($b) } @list; DESCRIPTION
Version objects were added to Perl in 5.10. This module implements version objects for older version of Perl and provides the version object API for all versions of Perl. All previous releases before 0.74 are deprecated and should not be used due to incompatible API changes. Version 0.77 introduces the new 'parse' and 'declare' methods to standardize usage. You are strongly urged to set 0.77 as a minimum in your code, e.g. use version 0.77; # even for Perl v.5.10.0 TYPES OF VERSION OBJECTS
There are two different types of version objects, corresponding to the two different styles of versions in use: Decimal Versions The classic floating-point number $VERSION. The advantage to this style is that you don't need to do anything special, just type a number into your source file. Quoting is recommended, as it ensures that trailing zeroes ("1.50") are preserved in any warnings or other output. Dotted Decimal Versions The more modern form of version assignment, with 3 (or potentially more) integers separated by decimal points (e.g. v1.2.3). This is the form that Perl itself has used since 5.6.0 was released. The leading 'v' is now strongly recommended for clarity, and will throw a warning in a future release if omitted. A leading 'v' character is required to pass the "is_strict()" test. DECLARING VERSIONS
If you have a module that uses a decimal $VERSION (floating point), and you do not intend to ever change that, this module is not for you. There is nothing that version.pm gains you over a simple $VERSION assignment: our $VERSION = "1.02"; Since Perl v5.10.0 includes the version.pm comparison logic anyways, you don't need to do anything at all. How to convert a module from decimal to dotted-decimal If you have used a decimal $VERSION in the past and wish to switch to a dotted-decimal $VERSION, then you need to make a one-time conversion to the new format. Important Note: you must ensure that your new $VERSION is numerically greater than your current decimal $VERSION; this is not always obvious. First, convert your old decimal version (e.g. 1.02) to a normalized dotted-decimal form: $ perl -Mversion -e 'print version->parse("1.02")->normal' v1.20.0 Then increment any of the dotted-decimal components (v1.20.1 or v1.21.0). How to "declare()" a dotted-decimal version use version; our $VERSION = version->declare("v1.2.3"); The "declare()" method always creates dotted-decimal version objects. When used in a module, you must put it on the same line as "use version" to ensure that $VERSION is read correctly by PAUSE and installer tools. You should also add 'version' to the 'configure_requires' section of your module metadata file. See instructions in ExtUtils::MakeMaker or Module::Build for details. Important Note: Even if you pass in what looks like a decimal number ("1.2"), a dotted-decimal will be created ("v1.200.0"). To avoid confusion or unintentional errors on older Perls, follow these guidelines: o Always use a dotted-decimal with (at least) three components o Always use a leading-v o Always quote the version If you really insist on using version.pm with an ordinary decimal version, use "parse()" instead of declare. See the "PARSING AND COMPARING VERSIONS" for details. See also version::Internals for more on version number conversion, quoting, calculated version numbers and declaring developer or "alpha" version numbers. PARSING AND COMPARING VERSIONS
If you need to compare version numbers, but can't be sure whether they are expressed as numbers, strings, v-strings or version objects, then you should use version.pm to parse them all into objects for comparison. How to "parse()" a version The "parse()" method takes in anything that might be a version and returns a corresponding version object, doing any necessary conversion along the way. o Dotted-decimal: bare v-strings (v1.2.3) and strings with more than one decimal point and a leading 'v' ("v1.2.3"); NOTE you can technically use a v-string or strings with a leading-v and only one decimal point (v1.2 or "v1.2"), but you will confuse both yourself and others. o Decimal: regular decimal numbers (literal or in a string) Some examples: $variable version->parse($variable) --------- ------------------------- 1.23 v1.230.0 "1.23" v1.230.0 v1.23 v1.23.0 "v1.23" v1.23.0 "1.2.3" v1.2.3 "v1.2.3" v1.2.3 See version::Internals for more on version number conversion. How to check for a legal version string If you do not want to actually create a full blown version object, but would still like to verify that a given string meets the criteria to be parsed as a version, there are two helper functions that can be employed directly: "is_lax()" The lax criteria corresponds to what is currently allowed by the version parser. All of the following formats are acceptable for dotted-decimal formats strings: v1.2 1.2345.6 v1.23_4 1.2345 1.2345_01 "is_strict()" If you want to limit yourself to a much more narrow definition of what a version string constitutes, "is_strict()" is limited to version strings like the following list: v1.234.5 2.3456 See version::Internals for details of the regular expressions that define the legal version string forms, as well as how to use those regular expressions in your own code if "is_lax()" and "is_strict()" are not sufficient for your needs. How to compare version objects Version objects overload the "cmp" and "<=>" operators. Perl automatically generates all of the other comparison operators based on those two so all the normal logical comparisons will work. if ( version->parse($v1) == version->parse($v2) ) { # do stuff } If a version object is compared against a non-version object, the non-object term will be converted to a version object using "parse()". This may give surprising results: $v1 = version->parse("v0.95.0"); $bool = $v1 < 0.96; # FALSE since 0.96 is v0.960.0 Always comparing to a version object will help avoid surprises: $bool = $v1 < version->parse("v0.96.0"); # TRUE Note that "alpha" version objects (where the version string contains a trailing underscore segment) compare as less than the equivalent version without an underscore: $bool = version->parse("1.23_45") < version->parse("1.2345"); # TRUE See version::Internals for more details on "alpha" versions. OBJECT METHODS
is_alpha() True if and only if the version object was created with a underscore, e.g. version->parse('1.002_03')->is_alpha; # TRUE version->declare('1.2.3_4')->is_alpha; # TRUE is_qv() True only if the version object is a dotted-decimal version, e.g. version->parse('v1.2.0')->is_qv; # TRUE version->declare('v1.2')->is_qv; # TRUE qv('1.2')->is_qv; # TRUE version->parse('1.2')->is_qv; # FALSE normal() Returns a string with a standard 'normalized' dotted-decimal form with a leading-v and at least 3 components. version->declare('v1.2')->normal; # v1.2.0 version->parse('1.2')->normal; # v1.200.0 numify() Returns a value representing the object in a pure decimal form without trailing zeroes. version->declare('v1.2')->numify; # 1.002 version->parse('1.2')->numify; # 1.2 stringify() Returns a string that is as close to the original representation as possible. If the original representation was a numeric literal, it will be returned the way perl would normally represent it in a string. This method is used whenever a version object is interpolated into a string. version->declare('v1.2')->stringify; # v1.2 version->parse('1.200')->stringify; # 1.200 version->parse(1.02_30)->stringify; # 1.023 EXPORTED FUNCTIONS
qv() This function is no longer recommended for use, but is maintained for compatibility with existing code. If you do not want to have it exported to your namespace, use this form: use version 0.77 (); is_lax() (Not exported by default) This function takes a scalar argument and returns a boolean value indicating whether the argument meets the "lax" rules for a version number. Leading and trailing spaces are not allowed. is_strict() (Not exported by default) This function takes a scalar argument and returns a boolean value indicating whether the argument meets the "strict" rules for a version number. Leading and trailing spaces are not allowed. AUTHOR
John Peacock <jpeacock@cpan.org> SEE ALSO
version::Internals. perl. perl v5.18.2 2014-01-06 version(3pm)
All times are GMT -4. The time now is 07:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy