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
GCORE(1)						      General Commands Manual							  GCORE(1)

NAME
gcore - get core image of running process SYNOPSIS
gcore [-s][-c core] pid DESCRIPTION
gcore creates a core image of each specified process, suitable for use with adb(1). By default the core image is written to the file <pid>.core. The options are: -c Write the core file to the specified file instead of <pid>.core. -s Stop the process while creating the core image and resume it when done. This makes sure that the core dump will be in a consistent state. The process is resumed even if it was already stopped. Of course, you can obtain the same result by manually stopping the process with kill(1). The core image name was changed from core.<pid> to <pid>.core to prevent matching names like core.h and core.c when using programs such as find(1). FILES
<process-id>.core The core image. BUGS
If gcore encounters an error while creating the core image and the -s option was used the process will remain stopped. Swapped out processes and system processes (the swapper) may not be gcore'd. 4.2 Berkeley Distribution April 15, 1994 GCORE(1)
All times are GMT -4. The time now is 11:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy