Sponsored Content
Top Forums Shell Programming and Scripting Reading specific range of columns in an Excel file Post 302929159 by Abhisrajput on Thursday 18th of December 2014 08:42:52 AM
Old 12-18-2014
Code:
#!/usr/bin/perl
use strict;
use warnings;
open my $fh, '<', 'CF_Resourcing' or die "Can't open file: $!\n";
while (<$fh>) {
    my @fields = split(/\t/);
    print "@fields[0,1,3,4,5,6,21,22,23,24,25,26,27,28,29,30,31,32,33]\n";
}


Last edited by Franklin52; 12-30-2014 at 07:59 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to convert fields from a text file to excel columns

i have this file which has the following contents: ,-0.3000 ,-0.3000 ,-0.3000 ,-0.9000 ,-0.9000 ,-0.9000 i would like to get this: -0.3-0.9-0.3-0.9-0.3-0.9 so far i am trying: awk '{for(i=1; i<=NF; i++) {printf("%f\n",$i)}}' test1 > test2 any help... (4 Replies)
Discussion started by: npatwardhan
4 Replies

2. Shell Programming and Scripting

How to sort columns in excel(csv) file

i want sort columns with headers based on another file headers file1 eg: i'm having an empty file with only coumn names like lastname firstname title expirydate stlcno status etc... another file with same column names and some other as well but in different order... file2 eg:firstname... (2 Replies)
Discussion started by: Man83Nagesh
2 Replies

3. UNIX for Dummies Questions & Answers

To compare first two columns in an excel file

Hi All, i have a excel sheet with two columns as below. column1 column2 100 100 200 300 300 400 400 400 500 600 i need to compare the values these two columns and the output should be printed in the third column...if these values are equal the output should be green and if these... (2 Replies)
Discussion started by: arunmanas
2 Replies

4. UNIX for Advanced & Expert Users

Finding a specific range of character in file

hi, I want to store from 102 character to 128 character to a variable of header record which can be identified as 'HDR' which is the first 3 characters in the same line of a same.txt file. Please advise. Thanks (4 Replies)
Discussion started by: techmoris
4 Replies

5. Shell Programming and Scripting

finding file with a specific range

Hi All, Thanks in advance File is generated with following format 31000000.xml to 48999999.xml 74000000.xml to 88999999.xml Above range should be find and moved into the folder named abc and below is another range should should be find and moved into folder named xyz ... (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

6. UNIX for Dummies Questions & Answers

How to delete columns with numbers in an excel file?

Dear all, I have one file (see below) with more then 100 columns and 2500 rows, and need only column which has GType in label with Alphabets, please help me to remove these columns with numbers. input file is n.201.GType n-201.Theta n-201.R n_1.GType n_1.Theta n_1.R... (6 Replies)
Discussion started by: AAWT
6 Replies

7. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

8. Shell Programming and Scripting

Need specific columns in a log file as excel.

Hi All... I am in need of few columns from a log file.. in .xls file... below is what i have tried. my log file has 16 colums with " ; " as delimiter, but i need randomn columns 1 2 3 4 5 6 10 11 16 in an excel. I tried to awk the columns with delimiter ; and it worked, below is the log... (5 Replies)
Discussion started by: nanz143
5 Replies

9. Shell Programming and Scripting

Perl script to accept specific columns from excel

Hi All, I have below perl script which writes xml from .xls file. Now i want to add below two conditions in this script : 1. to check if the the input .xls file has ony two columns , if more tahn two columns then script should pop up an error. 2. If there are two columns , then first column... (4 Replies)
Discussion started by: omkar.jadhav
4 Replies

10. Shell Programming and Scripting

Trouble reading from a tab delimited excel file

So I have a file1.txt that is tab delimited: e.g. FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 9545641 123 "Neighbor and Labrador,Canada" 54895 'CANADA' 9456465 456 "Neighbor and Labrador,Canada" 54893 'CANADA' 8746512 789 "Neighbor and... (11 Replies)
Discussion started by: dan139
11 Replies
Regexp::RegGrp(3pm)					User Contributed Perl Documentation				       Regexp::RegGrp(3pm)

NAME
Regexp::RegGrp - Groups a regular expressions collection VERSION
Version 1.002 DESCRIPTION
Groups regular expressions to one regular expression SYNOPSIS
use Regexp::RegGrp; my $reggrp = Regexp::RegGrp->new( { reggrp => [ { regexp => '%name%', replacement => 'John Doe', modifier => $modifier }, { regexp => '%company%', replacement => 'ACME', modifier => $modifier } ], restore_pattern => $restore_pattern } ); $reggrp->exec( $scalar ); To return a scalar without changing the input simply use (e.g. example 2): my $ret = $reggrp->exec( $scalar ); The first argument must be a hashref. The keys are: reggrp (required) Arrayref of hashrefs. The keys of each hashref are: regexp (required) A regular expression replacement (optional) Scalar or sub. A replacement for the regular expression match. If not set, nothing will be replaced except "store" is set. In this case the match is replaced by something like sprintf("x01%dx01", $idx) where $idx is the index of the stored element in the store_data arrayref. If "store" is set the default is: sub { return sprintf( "x01%dx01", $_[0]->{store_index} ); } If a custom restore_pattern is passed to to constructor you MUST also define a replacement. Otherwise it is undefined. If you define a subroutine as replacement an hashref is passed to this subroutine. This hashref has four keys: match Scalar. The match of the regular expression. submatches Arrayref of submatches. store_index The next index. You need this if you want to create a placeholder and store the replacement in the $self->{store_data} arrayref. opts Hashref of custom options. modifier (optional) Scalar. The default is 'sm'. store (optional) Scalar or sub. If you define a subroutine an hashref is passed to this subroutine. This hashref has three keys: match Scalar. The match of the regular expression. submatches Arrayref of submatches. opts Hashref of custom options. A replacement for the regular expression match. It will not replace the match directly. The replacement will be stored in the $self->{store_data} arrayref. The placeholders in the text can easily be rereplaced with the restore_stored method later. restore_pattern (optional) Scalar or Regexp object. The default restore pattern is qr~x01(d+)x01~ This means, if you use the restore_stored method it is looking for x010x01, x011x01, ... and replaces the matches with $self->{store_data}->[0], $self->{store_data}->[1], ... EXAMPLES
Example 1 Common usage. #!/usr/bin/perl use strict; use warnings; use Regexp::RegGrp; my $reggrp = Regexp::RegGrp->new( { reggrp => [ { regexp => '%name%', replacement => 'John Doe' }, { regexp => '%company%', replacement => 'ACME' } ] } ); open( INFILE, 'unprocessed.txt' ); open( OUTFILE, '>processed.txt' ); my $txt = join( '', <INFILE> ); $reggrp->exec( $txt ); print OUTFILE $txt; close(INFILE); close(OUTFILE); Example 2 A scalar is requested by the context. The input will remain unchanged. #!/usr/bin/perl use strict; use warnings; use Regexp::RegGrp; my $reggrp = Regexp::RegGrp->new( { reggrp => [ { regexp => '%name%', replacement => 'John Doe' }, { regexp => '%company%', replacement => 'ACME' } ] } ); open( INFILE, 'unprocessed.txt' ); open( OUTFILE, '>processed.txt' ); my $unprocessed = join( '', <INFILE> ); my $processed = $reggrp->exec( $unprocessed ); print OUTFILE $processed; close(INFILE); close(OUTFILE); AUTHOR
Merten Falk, "<nevesenin at cpan.org>" BUGS
Please report any bugs or feature requests through the web interface at http://github.com/nevesenin/regexp-reggrp-perl/issues <http://github.com/nevesenin/regexp-reggrp-perl/issues>. SUPPORT
You can find documentation for this module with the perldoc command. perldoc Regexp::RegGrp COPYRIGHT &; LICENSE Copyright 2010, 2011 Merten Falk, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-02-18 Regexp::RegGrp(3pm)
All times are GMT -4. The time now is 08:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy