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
apache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR:UserDContributed Perl Docuapache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR::UUID(3)

NAME
APR::UUID - Perl API for manipulating APR UUIDs Synopsis use APR::UUID (); # get a random UUID and format it as a string my $uuid = APR::UUID->new->format; # $uuid = e.g. 'd48889bb-d11d-b211-8567-ec81968c93c6'; # same as the object returned by APR::UUID->new my $uuid_parsed = APR::UUID->parse($uuid); Description "APR::UUID" is used to get and manipulate random UUIDs. It allows you to "create" random UUIDs, which when "formatted" returns a string like: 'd48889bb-d11d-b211-8567-ec81968c93c6'; which can be parsed back into the "APR::UUID" object with "parse()". API
"APR::UUID" provides the following functions and/or methods: "format" Convert an "APR::UUID object" object into a string presentation: my $uuid_str = $uuid->format; obj: $uuid ( "APR::UUID object" ) ret: $uuid_str returns a string representation of the object (.e.g 'd48889bb-d11d-b211-8567-ec81968c93c6'). since: 2.0.00 "new" Create a "APR::UUID object" using the random engine: my $uuid = APR::UUID->new; class: "APR::UUID" ( "APR::UUID class" ) ret: $uuid ( "APR::UUID object" ) since: 2.0.00 "DESTROY" $uuid->DESTROY; obj: "APR::UUID" ( "APR::UUID object" ) ret: no return value since: 2.0.00 Do not call this method, it's designed to be only called by Perl when the variable goes out of scope. If you call it yourself you will get a segfault when perl will call DESTROY on its own. "parse" Convert a UUID string into an "APR::UUID object" object: $uuid = APR::UUID->parse($uuid_str) arg1: $uuid_str (string) UUID string (.e.g 'd48889bb-d11d-b211-8567-ec81968c93c6') ret: $uuid ( "APR::UUID object" ) The new object. since: 2.0.00 See Also mod_perl 2.0 documentation. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.16.2 2011-02-07 apache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR::UUID(3)
All times are GMT -4. The time now is 01:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy