Sponsored Content
Top Forums Shell Programming and Scripting editing file with awk cut and sed Post 302628889 by birei on Tuesday 24th of April 2012 05:36:36 AM
Old 04-24-2012
Hi mimilaw,

How about perl?
Code:
$ cat infile
2,"102343454",5060,"579668","579668","579668","SIP",,,"825922","035885221283026",1,268,"00:59:00.782 APR 17 2012","00:59:00.815 APR 17 2012","01:03:28.550 APR 17 2012",1,"M10",1,"M10",1,"core-veraz","core-hammer","localhost:325184","G729","audio","core-hammer","3045684523",10012,"4958033045",61696,"core-veraz","560584321",61698,"6540340321",10012,0,0,0,0,0,0,0,0,0,0,0,0,"325185","G449","CAT","coreB","100109148213",10012,"106504021",61698,"coreA","10.50.0.1",61696,"10.0.0.0",10012,0,0,0,0,0,0,0,0,0,0,0,0,,,,,"0.0.0.0",0,"0.0.0.0",0,,"0.0.0.0",0,"0.0.0.0",0,0,0,0,0,0,0,0,0,0,0,,,,,
$ cat script.pl
use warnings;
use strict;
use Text::CSV_XS;

die qq[Usage: perl $0 <input-file> <output-file>\n] unless @ARGV == 2;

open my $ofh, q[>], pop or die qq[Open: $!\n];

my %month;

{
        my $month;
        %month = map { $_ => sprintf q[%02d], ++$month } 
                qw( jan feb mar apr may jun jul aug sep oct nov dec );
}

## Date fields are 13..15

my $csv = Text::CSV_XS->new();

while ( my $row = $csv->getline( \*ARGV ) ) {
        for ( @$row[13 .. 15] ) {
                my @f = split;
                $f[1] = $month{ lc $f[1] };
                $_ = join q[], @f;
        }
        $csv->print( $ofh, $row );
        print $ofh qq[\n];
}
$ perl script.pl infile outfile
$ cat outfile
2,102343454,5060,579668,579668,579668,SIP,,,825922,035885221283026,1,268,00:59:00.78204172012,00:59:00.81504172012,01:03:28.55004172012,1,M10,1,M10,1,core-veraz,core-hammer,localhost:325184,G729,audio,core-hammer,3045684523,10012,4958033045,61696,core-veraz,560584321,61698,6540340321,10012,0,0,0,0,0,0,0,0,0,0,0,0,325185,G449,CAT,coreB,100109148213,10012,106504021,61698,coreA,10.50.0.1,61696,10.0.0.0,10012,0,0,0,0,0,0,0,0,0,0,0,0,,,,,0.0.0.0,0,0.0.0.0,0,,0.0.0.0,0,0.0.0.0,0,0,0,0,0,0,0,0,0,0,0,,,,,

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cut vs. sed vs. awk ?

hi again...need new help guys:p the file contains following infos... users/abc/bla1.exe newusers/defgh/ik/albg2.exe users2/opww/ertz/qqwertzu/rwerwew.exe how to get the file content into... users/abc/ newusers/defgh/ik/ users2/opww/ertz/qqwertzu/ with... you can erase the... (5 Replies)
Discussion started by: svennie
5 Replies

2. Shell Programming and Scripting

Editing File using awk/sed

Hello Awk Gurus, Can anyone of you help me with the below problem. I have got a file having data in below format pmFaultyTransportBlocks ----------------------- 9842993 pmFrmNoOfDiscRachFrames ----------------------- NULL pmNoRecRandomAccSuccess -----------------------... (4 Replies)
Discussion started by: Mohammed
4 Replies

3. Shell Programming and Scripting

awk,sed or cut problem

Good afternoon, Sir's, I would like to seek your assistance regarding on this matter. $cat file1 111 aaaa bbb aass aaa files file1 temp temp1 pix 222 11 22 1 33 44 desired output: aaaa bbb aass files file1 temp1 222 11 22 1 33 44 thanks (7 Replies)
Discussion started by: invinzin21
7 Replies

4. Shell Programming and Scripting

cut in sed/awk

Hi Can i have an example where i should be able to cut columns (like for eg cut -c 1-3) in sed or awk. Regards Dhana (12 Replies)
Discussion started by: dhanamurthy
12 Replies

5. Shell Programming and Scripting

Sed Awk Cut Grep Combination Help ?

I have been reading for a few hours trying to educate myself enough to accomplish this task, so please know I have performed some research. Unfortunately, I am not a *NIX scripting expert, or a coder. I come from a network background instead. SO, here is my desired outcome. I have some Cisco... (5 Replies)
Discussion started by: abbzer0
5 Replies

6. Homework & Coursework Questions

String editing using sed? awk?

1. The problem statement, all variables and given/known data: Problem Statement for project: When an account is created on the CS Unix network, a public html directory is created in the account's home directory. A default web page is put into that directory. Some users replace or... (13 Replies)
Discussion started by: peage1475
13 Replies

7. Shell Programming and Scripting

Substring using cut/awk/sed

Hi Gurus,I have a seemingly simple problem but struggling with it.It is as follows : I/p string - ABCDEFGHIJ20100909.txt desired o/p - AB,DEF,20100909,ABCDEFGHIJ20100909.txt How to achieve it ?Thanks in advance. Please use code tags, thank you (20 Replies)
Discussion started by: sumoka
20 Replies

8. Shell Programming and Scripting

sed or awk editing help

Hi all I use aix (sadly). I've got a file consisting of fields separated by commas, I need a sed or awk command that will delete all spaces between two commas as long as there are only spaces between the commas. eg ,abc, ,sd , ,dr at would become ,abc,,sd ,,dr at I have... (53 Replies)
Discussion started by: mychmose
53 Replies

9. Shell Programming and Scripting

Line/Variable Editing for Awk sed Cut

Hello, i have a file, i open the file and read the line, i want to get the first item in the csv file and also teh third+6 item and wirte it to a new csv file. only problem is that using echo it takes TOO LONG: please help a newbie. below is my code: WorkingDir=$1 FileName=`cut -d ',' -f... (2 Replies)
Discussion started by: limamichelle
2 Replies

10. Shell Programming and Scripting

Awk/sed/cut to filter out records from a file based on criteria

I have two files and would need to filter out records based on certain criteria, these column are of variable lengths, but the lengths are uniform throughout all the records of the file. I have shown a sample of three records below. Line 1-9 is the item number "0227546_1" in the case of the first... (15 Replies)
Discussion started by: MIA651
15 Replies
PERLIO(1)						User Contributed Perl Documentation						 PERLIO(1)

NAME
APR:PerlIO -- An APR Perl IO layer SYNOPSIS
use APR::PerlIO (); sub handler { my $r = shift; open my $fh, ">:APR", $filename, $r or die $!; # work with $fh as normal $fh close $fh; return Apache::OK; } DESCRIPTION
"APR::PerlIO" implements a Perl IO layer using APR's file manipulation as its internals. Why do you want to use this? Normally you shouldn't, probably it won't be faster than Perl's default layer. It's only useful when you need to manipulate a filehandle opened at the APR side, while using Perl. Normally you won't call open() with APR layer attribute, but some mod_perl functions will return a filehandle which is internally hooked to APR. But you can use APR Perl IO directly if you want. METHODS
Perl Interface: open() To use APR Perl IO to open a file the four arguments open() should be used. For example: open my $fh, ">:APR", $filename, $r or die $!; where: the second argument is the mode to open the file, constructed from two sections separated by the ":" character: the first section is the mode to open the file under (>, <, etc) and the second section must be a string APR. the fourth argument can be a "Apache::RequestRec" or "Apache::ServerRec" object. the rest of the arguments are the same as described by the open() manpage. seek() seek($fh, $offset, $whence); If $offset is zero, "seek()" works normally. However if $offset is non-zero and Perl has been compiled with with large files support ("-Duselargefiles"), whereas APR wasn't, this function will croak. This is because largefile size "Off_t" simply cannot fit into a non-largefile size "apr_off_t". To solve the problem, rebuild Perl with "-Uuselargefiles". Currently there is no way to force APR to build with large files support. The C interface provides functions to convert between Perl IO and APR Perl IO filehandles. SEE ALSO
The perliol(1), perlapio(1) and perl(1) manpages. perl v5.8.0 2002-06-05 PERLIO(1)
All times are GMT -4. The time now is 06:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy