Sponsored Content
Full Discussion: Merge broken lines
Top Forums Shell Programming and Scripting Merge broken lines Post 302625651 by birei on Wednesday 18th of April 2012 04:48:32 AM
Old 04-18-2012
Try next one. Run it with your particular options.
Code:
$ cat script2.pl 
use warnings;
use strict;
use Getopt::Long;
use File::Copy qw( move copy );
use File::Spec;

my ($destdir, $bakdir);

GetOptions(
        q[destdir=s] => \$destdir,
        q[bakdir=s] => \$bakdir,
) or die qq[ERROR reading arguments\n];

die qq[Usage: perl $0 --destdir=<dir> --bakdir=<dir> <files>\n] 
        unless defined $destdir &&
                   defined $bakdir &&
                   -d $destdir &&
                   -d $bakdir;


for my $file ( @ARGV ) {
        next if -s $file;
        my $efile = substr $file, 0, 8;
        do {
                local $^I = q[.bak];
                local @ARGV = $efile;
                my @prev_line;
                while ( <> ) {
                        chomp;

                        if ( /\A\*\*/ .. eof ) {
                                        next if m/\A\s*\Z/;
                                        if ( m/¦/ ) {
                                                        if ( @prev_line ) {
                                                                        printf qq[%s\n], pop @prev_line;
                                                        }
                                                        push @prev_line, $_;
                                                        next;
                                        }

                                        printf qq[%s\n], (pop @prev_line || qq[]) . $_;
                                        next;
                        }

                        printf qq[%s\n], $_;
                }

                {
                        my $f = $efile . $^I;
                        move( 
                                $f,
                                File::Spec->catfile( $bakdir, $f ) 
                        ) || warn qq[Couldn't move file $f\n];
                }

                move(
                        $efile,
                        File::Spec->catfile( $destdir, $efile )
                ) || warn qq[Couldn't move file $efile\n];

                move(
                        $file,
                        File::Spec->catfile( $bakdir, $file )
                ) || warn qq[Couldn't move file $file\n];

                {
                        my $f = $efile . qq[Service];
                        move(
                                $f,
                                File::Spec->catfile( $bakdir, $f )
                        ) || warn qq[Couldn't move file $f\n];
                }
        }

}
$ perl ../script2.pl  --destdir=../IN --bakdir=../failed /tmp/grep/*

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk / shell - Fix broken lines and data

Gurus, I am struggling with a issue and thought I could use some of your expertise. Need Help with this I have a flat file that has millions of records 24|john|account ~ info |56| 25|kuo|account ~ journal |58| 27|kim|account ~ journal |59| 28|San|account ~ journal |60|... (3 Replies)
Discussion started by: rimss
3 Replies

2. Shell Programming and Scripting

Merge two lines

Hi I have two lines of data formatted as displayed below shop, price, remark, date a,#N/A,order to -fd, 20091011 and would like it to be shop:a price:#N/A remark:order to -fd date:20091011 How can I do it? Many thanks (2 Replies)
Discussion started by: lalelle
2 Replies

3. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

4. Shell Programming and Scripting

Joining broken lines

I have a plain test file with a delimeter ''. In this file some lines are broken into two. The first part of these broken line will have 6 columns and the second part will have 4. These broken lines will be consicutive. I want to join the two consicutive lines which are having 6 fields and 4... (8 Replies)
Discussion started by: ratheeshjulk
8 Replies

5. UNIX for Dummies Questions & Answers

How to identify broken lines in a file?

Hi, I have a 100 byte length fixed width file . In that three rows are broken and went off to next line. How can I identify the broken lines? E.g. ABCD1234MNRD4321 abcd1234mnrd 4321 As you can see in my example my second row with small case alphabets is broken... (5 Replies)
Discussion started by: okkadu
5 Replies

6. Shell Programming and Scripting

Merge lines

Hello I have a file with CAR 23 COLOR 12 CAR 44 COLOR 12 CAR 55 COLOR 20 SIZE BIG CAR 56 CAR 57 COLOR 11 How can merge the CAR and the COLOR + SIZE (if there are COLOR,SIZE) CAR 23 COLOR 12 CAR 44 COLOR 12 CAR 55 COLOR 20 SIZE BIG CAR 56 CAR 57 COLOR 11 Every line begin in... (4 Replies)
Discussion started by: sharong
4 Replies

7. Shell Programming and Scripting

Joining broken lines with awk or perl

Hi, I have a huge file with sql broken statements like: PP3697HB @@@@0 <<<<<<Record has been deleted as per PP3697HB>>>>>> FROM sys.xtab_ref rc,sys.xtab_sys f,sys.domp ur WHE RE rc.milf = ur.milf AND rc.molf = f.molf AND ur.dept = 'SWIT'AND ur .department = 'IND' AND share = '2' AND... (4 Replies)
Discussion started by: som.nitk
4 Replies

8. Shell Programming and Scripting

Merge Lines

Hello I have an input as below this is test we are( ) one end of description I am looking for output this is test we are () one end of description (2 Replies)
Discussion started by: Tomlight
2 Replies

9. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies
File::Spec::Cygwin(3pm) 				 Perl Programmers Reference Guide				   File::Spec::Cygwin(3pm)

NAME
File::Spec::Cygwin - methods for Cygwin file specs SYNOPSIS
require File::Spec::Cygwin; # Done internally by File::Spec if needed DESCRIPTION
See File::Spec and File::Spec::Unix. This package overrides the implementation of these methods, not the semantics. This module is still in beta. Cygwin-knowledgeable folks are invited to offer patches and suggestions. canonpath Any "" (backslashes) are converted to "/" (forward slashes), and then File::Spec::Unix canonpath() is called on the result. file_name_is_absolute True is returned if the file name begins with "drive_letter:", and if not, File::Spec::Unix file_name_is_absolute() is called. tmpdir (override) Returns a string representation of the first existing directory from the following list: $ENV{TMPDIR} /tmp $ENV{'TMP'} $ENV{'TEMP'} C:/temp Since Perl 5.8.0, if running under taint mode, and if the environment variables are tainted, they are not used. case_tolerant Override Unix. Cygwin case-tolerance depends on managed mount settings and as with MsWin32 on GetVolumeInformation() $ouFsFlags == FS_CASE_SENSITIVE, indicating the case significance when comparing file specifications. Default: 1 COPYRIGHT
Copyright (c) 2004,2007 by the Perl 5 Porters. 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.18.2 2014-01-06 File::Spec::Cygwin(3pm)
All times are GMT -4. The time now is 09:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy