Sponsored Content
Top Forums Shell Programming and Scripting how to get split output of a file, using perl script Post 302347467 by durden_tyler on Tuesday 25th of August 2009 07:19:33 PM
Old 08-25-2009
Here's one way to do it in Perl:

Code:
$ 
$ cat data.log.1
###s1
main.build.3495
main.build.199
main.build.3408

###s2
main.build.3495
main.build.3408
main.build.199
$ 
$ ##
$ perl -ne 'chomp;
>           if (/^###s1/) {$s1=true} elsif(/^###s2/) {$s2=true}
>           if ($s2) {push @s2,$_} elsif($_ ne "" && $s1) {push @s1,$_}
>           END {print "Array \@s1:\n";foreach $i (@s1) {print $i,"\n"}
>                print "Array \@s2:\n";foreach $i (@s2) {print $i,"\n"}}' data.log.1
Array @s1:
###s1
main.build.3495
main.build.199
main.build.3408
Array @s2:
###s2
main.build.3495
main.build.3408
main.build.199
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Script : Split given month into weeks

I want to split a given month into weeks. For example if I give the date in dd/mm/yy format say 01/02/08 it should give output in the given format : week1 : start date and end date. week2 : "" week3 : "" week4 : "" (5 Replies)
Discussion started by: khushbu_roy
5 Replies

2. Shell Programming and Scripting

Perl script error to split huge data one by one.

Below is my perl script: #!/usr/bin/perl open(FILE,"$ARGV") or die "$!"; @DATA = <FILE>; close FILE; $join = join("",@DATA); @array = split( ">",$join); for($i=0;$i<=scalar(@array);$i++){ system ("/home/bin/./program_name_count_length MULTI_sequence_DATA_FILE -d... (5 Replies)
Discussion started by: patrick87
5 Replies

3. Shell Programming and Scripting

Perl Split for text in file

Hi all I have written Perl script to swap the strings in the second a third column from a text file. My input file format is : the|empty|the|det lake|empty|lake|conj_and was|empty|was|auxpass drained|empty|drained|conj_and birds|empty|bird|s|nn The expected output file format is... (11 Replies)
Discussion started by: my_Perl
11 Replies

4. Shell Programming and Scripting

How do I split file into pieces with PERL?

How do I split file into pieces with PERL? IE file.txt head 1 2 3 4 end head 5 6 7 8 9 end n so on (7 Replies)
Discussion started by: 3junior
7 Replies

5. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

6. Shell Programming and Scripting

Output after a perl script gives a file with size zero.

Hi, I have a unix shell script which generates a flat file after connecting to Teradata servers to fetch tables and views and also picks up modified unix scripts from the specified paths. Later on the script calls a perl script to assign a value based on the type of object in the flat file which... (2 Replies)
Discussion started by: yohasini
2 Replies

7. Shell Programming and Scripting

perl script to split the filename

In PERL script I have few files named theme1.htm,theme2.htm,theme3.htm and so on. now I need to write perl code to split the the filename and store only that particular digit. Example -------------- filename is theme1.htm output should be 1 another example ---------------... (5 Replies)
Discussion started by: giridhar276
5 Replies

8. Shell Programming and Scripting

perl script to split the text file after every 4th field

I had a text file(comma seperated values) which contains as below 196237,ram,25-May-06,ram.kiran@xyz.com,204183,Pavan,4-Jun-07,Pavan.Desai@xyz.com,237107,ram Chandra,15-Mar-10,ram.krishna@xyz.com ... (3 Replies)
Discussion started by: giridhar276
3 Replies

9. Shell Programming and Scripting

Oneliner ---split string to character by piping shell output to perl

Hello, I was trying to split a string to characters by perl oneliner. echo "The quick brown fox jumps over the lazy dog" | perl -e 'split // ' But did not work as with bash script pipe: echo "The quick brown fox jumps over the lazy dog" | fold -w1 | sort | uniq -ic 8 1 T 1... (6 Replies)
Discussion started by: yifangt
6 Replies

10. Shell Programming and Scripting

Modification of perl script to split a large file into chunks of 5000 chracters

I have a perl script which splits a large file into chunks.The script is given below use strict; use warnings; open (FH, "<monolingual.txt") or die "Could not open source file. $!"; my $i = 0; while (1) { my $chunk; print "process part $i\n"; open(OUT, ">part$i.log") or die "Could... (4 Replies)
Discussion started by: gimley
4 Replies
Dist::Zilla::App::Command::build(3pm)			User Contributed Perl Documentation		     Dist::Zilla::App::Command::build(3pm)

NAME
Dist::Zilla::App::Command::build - build your dist VERSION
version 4.300020 SYNOPSIS
dzil build [ --trial ] [ --tgz | --no-tgz ] [ --in /path/to/build/dir ] DESCRIPTION
This command is a very thin layer over the Dist::Zilla "build" method, which does all the things required to build your distribution. By default, it will also archive your distribution and leave you with a complete, ready-to-release distribution tarball. EXAMPLE
$ dzil build $ dzil build --no-tgz $ dzil build --in /path/to/build/dir OPTIONS
--trial This will build a trial distribution. Among other things, it will generally mean that the built tarball's basename ends in -TRIAL. --tgz | --no-tgz Builds a .tar.gz in your project directory after building the distribution. --tgz behaviour is by default, use --no-tgz to disable building an archive. --in Specifies the directory into which the distribution should be built. If necessary, the directory will be created. An archive will not be created. AUTHOR
Ricardo SIGNES <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ricardo SIGNES. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-21 Dist::Zilla::App::Command::build(3pm)
All times are GMT -4. The time now is 10:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy