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

Name
       ex, edit - text editor

Syntax
       ex [ - ] [ -v ] [ -x ] [ -t tag ] [ -r ] [ +command ] [ -l ] name...
       edit [ ex options ]

Description
       The  editor  is	the  root  of a family of editors: and The editor is a superset of with the most notable extension being a display-editing
       facility.  Display-based editing is the focus of

       The name argument indicates the files to be edited.

Options
       -    Suppresses all interactive-user feedback.  This option is useful in processing editor scripts in command files.

       -v   Equivalent to using rather than

       -t   Equivalent to an initial tag command, that is, editing the file containing the tag and positioning the editor at its definition.

       -r   Used to recover after an editor or system crash.  It recovers by retrieving the last saved version of the named file.  If no  file	is
	    specified, it displays a list of saved files.

       -R   Sets the read-only option at the start.

       +command
	    Indicates  that  the editor should begin by executing the specified command.  If the command is omitted, it defaults to $, positioning
	    the editor at the last line of the first file, initially.  Other useful commands here are scanning patterns of the form  +/pattern	or
	    line numbers.

       -l   Sets up for LISP.  That is, it sets the showmatch and lisp options.  The -x option is available only if the Encryption layered product
	    is installed.

       -x   Causes to prompt for a key. The key is used to encrypt and decrypt the contents of the file. If the file contents have been  encrypted
	    with one key, you must use the same key to decrypt them.

Restrictions
       The command causes all marks to be lost on lines changed and then restored if the marked lines were changed.

       The command does not clear the buffer modified condition.

       The z command prints a number of logical rather than physical lines.  More than a screenful of output may result if long lines are present.

       File input/output errors do not print a name if the command line minus sign (-) option is used.

       There is no easy way to do a single scan ignoring case.

       The editor does not warn you if you place text in named buffers and do not use it before exiting the editor.

       Null characters are discarded from input files, and cannot appear in output files.

Files
       /usr/lib/ex?.?recover	     recover command
       /usr/lib/ex?.?preserve	     preserve command
       /etc/termcap		terminal capabilities
       ~/.exrc			editor startup file
       /tmp/Exnnnnn		editor temporary
       /tmp/Rxnnnnn		named buffer temporary
       /usr/preserve		preservation directory

See Also
       awk(1), ed(1), grep(1), sed(1), vi(1), termcap(5), environ(7)
       "Edit: A Tutorial" and the "Ex Reference Manual" in the
       Supplementary Documents, Volume 1: General User

																	     ex(1)
All times are GMT -4. The time now is 01:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy