Sponsored Content
Top Forums Shell Programming and Scripting Another tricky sed or awk question Post 302429842 by pseudocoder on Tuesday 15th of June 2010 06:51:05 PM
Old 06-15-2010
Code:
$ perl -F, -ane '{
                  if ( @A[0] eq "" ) { push @A, @F ; }
                  elsif ( $A[0] ne "" && $A[0] eq $F[0] ) { $A[2]="$A[2]-$F[2]"; }
                  elsif ( $A[0] ne "" && $A[0] ne $F[0] ) { print "$A[0],$A[1],$A[2],$A[3],$A[4]" ; @A=(); push @A, @F; }
                }
                 END
                {
                  print "$A[0],$A[1],$A[2],$A[3],$A[4]"; 
                }' infile

 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Tricky File Permission Question

I'm trying to answer the following question about file permissions in Unix. Consider a file with the following permissions: rwx---r-- I am not the owner of this file, but I am a member of the group of this file. My question is: do I have read access to this file? I thought... (3 Replies)
Discussion started by: Hook
3 Replies

2. Shell Programming and Scripting

Tricky Sed

Hello. I am trying to convert occurrences of 'NULL' from a datafile. The 'NULL' occurences appears at this: |NULL| NULL|NULL| NULL|NULL| NULL|NULL| NULL| There should be 52 fields per line. I would like any occurrence of | NULL| or |NULL| to appear as '||' Currently I am using this sed... (2 Replies)
Discussion started by: bestbuyernc
2 Replies

3. Shell Programming and Scripting

Tricky script question

Hi, I'm in the midst of writing a UNIX script that sftp's files to an external host and am stuck with a problem. The problem is that the files created on my server as a order number that correlates to a sequence of directories on the remote host which is where the file should be ftp'ed. ... (3 Replies)
Discussion started by: budrito
3 Replies

4. UNIX for Dummies Questions & Answers

Tricky Quotation Question

Hi, I am at a point in my script where I defined the number of the command line parameter I would like to set a variable equal to: parameter_number=14 I would then like to set a variable equal to the correct parameter: variable=$parameter_number The issue here is that {} is required... (2 Replies)
Discussion started by: msb65
2 Replies

5. Shell Programming and Scripting

sed or awk question

Hello expert, I have an output file with few thousand lines similar like below : "Future Netmgmt" "10.99.16.0" "N" "10" "10.0.0.0" "Circuitless-IP" " " "255.255.254.0" "Future Netmgmt" "10.99.18.0" "N" "10" "10.0.0.0" "Circuitless-IP" " " "255.255.254.0" "WAAS loopbacks" "10.99.20.0"... (6 Replies)
Discussion started by: dannytrinh
6 Replies

6. Shell Programming and Scripting

Tricky sed or awk question

Hello everyone, unfortunately I am no unix nor scripting guru, which is why I am asking for help here. I am trying to reformat a .csv file using sed or awk which has the following format: a,b,C-D-E,f,g h,i,J,k,l m,n,O-P-Q-R-S,t,u v,w,X-Y,z,a It's basically a 5-field text file which has an... (7 Replies)
Discussion started by: awayand
7 Replies

7. Shell Programming and Scripting

sed tricky problem

Hi, I have a file which contains two strings: AAAAA and BBBBB I have two variables in my script: DATE="03/21/2010" aDate="20100321" I need to replace string AAAAA with variable $DATE and BBBBB with $aDate. Here is what I do sed "s/AAAAA/$DATE/" $BASIC_TMPLT | sed "s/BBBBB/$aDate/" >... (4 Replies)
Discussion started by: axed
4 Replies

8. UNIX for Dummies Questions & Answers

Tricky GREP question..

I have some large login files that I need to extract (user)@(server) from. Where it gets tricky is that there is usually more than one '@' sign on each line(although it does have a leading space if it's not part of the (user)@(server) string), I need only the (user)@(server) section, I need only... (6 Replies)
Discussion started by: Mordaris
6 Replies

9. Shell Programming and Scripting

Tricky BASH quoting question

I have some data files that I can identify by a certain pattern in the names using find. Every one of those data files has an XML file associated with it (can be multiple data files per XML file). The XML file is always up one directory from the data file(s) in a folder calledRun##### -... (12 Replies)
Discussion started by: Michael Stora
12 Replies

10. Shell Programming and Scripting

Tricky sed required

Hi All I need to put some sed together for a task and its a bit advanced for me, so I thought I'd ask if anyone here could help. I have a csv file with content like this - "","abcde","","" "'","abcde","","" "","","","1234" "'e'","","","" I need to remove any single quotes that fall... (17 Replies)
Discussion started by: steadyonabix
17 Replies
Perl::Critic::Policy::ControlStructures::ProhibitCascadiUserEContributed PerlPerl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse(3pm)

NAME
Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse - Don't write long "if-elsif-elsif-elsif-elsif...else" chains. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
Long "if-elsif" chains are hard to digest, especially if they are longer than a single page or screen. If testing for equality, use a hash lookup instead. If you're using perl 5.10 or later, use "given"/"when". if ($condition1) { #ok $foo = 1; } elsif ($condition2) { #ok $foo = 2; } elsif ($condition3) { #ok $foo = 3; } elsif ($condition4) { #too many! $foo = 4; } else { #ok $foo = $default; } CONFIGURATION
This policy can be configured with a maximum number of "elsif" alternatives to allow. The default is 2. This can be specified via a "max_elsif" item in the .perlcriticrc file: [ControlStructures::ProhibitCascadingIfElse] max_elsif = 3 AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-0Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse(3pm)
All times are GMT -4. The time now is 11:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy