Rename with a different condition

Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-21-2016
Rename with a different condition

Hello

I have a file like this

Code:
a aa:::+
b aa:::+
c aa:::-
d ab:::+
e ab:::+
f ac:::+
g ac:::+
h ac:::-

Desired output


Code:
a aa:::+
b aa:::+
c aa.1:::-
d ab:::+
e ab:::+
f ac:::+
g ac:::+
h ac.1:::-

Logic
a. dont worry about column1.
b. in column2, after the tri-colon delimiter look at the plus (or) minus sign.
c. if the name (aa,ab...) before the tri-colon delimiter is same but is having a different sign compared to the other records with the same name, then append this records name with the occurrence number

Thanks
# 2  
Old 11-21-2016
What operating system are you using?

What shell are you using?

With well over 350 posts in this forum we would expect that you would have a very good idea of how to handle a request like this yourself! What have you tried to solve this problem on your own?
# 3  
Old 11-21-2016
Hi Don,

I did try this from an online search

Code:
awk 'cnt[$2]++{$2=$2":::"cnt[$2]-1} 1'

But it doesn't take the plus or minus sign into consideration.
# 4  
Old 11-21-2016
Quote:
Originally Posted by jacobs.smith
Hi Don,

I did try this from an online search

Code:
awk 'cnt[$2]++{$2=$2":::"cnt[$2]-1} 1'

But it doesn't take the plus or minus sign into consideration.
Moderator's Comments:
Mod Comment You didn't answer the first two questions I asked at all. And, the real answer to the third question appears to be that you did not make any attempt to solve this problem on your own. The code you found on your online search does not meet any of your requirements and you clearly did not make any attempt to solve this problem using what you had learned from the help you have been provided in this forum for almost five years.

You have asked 140 questions and gotten answers to 139 of them that were intended to help you learn how to use the shell, awk, and other tools; but instead of trying to learn anything about how to write your own code, you seem to think of The UNIX & Linux Forums as your unpaid programming staff despite being warned that you would be banned if you continued this behavior.

You are hereby banned from this site.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Using rename kristinu Shell Programming and Scripting 1 02-20-2018 02:08 PM
Using rename kristinu UNIX for Dummies Questions & Answers 4 03-23-2014 06:19 PM
If condition return 0 even when it fails to satisfy te condition Priya Amaresh Shell Programming and Scripting 2 05-10-2013 01:54 AM
redirect stdout echo command in condition A run in condition B jao_madn Shell Programming and Scripting 3 11-02-2011 09:01 PM
Difference between [condition] and [[condition]] and ((condition)) when used with if condition soumyabubun HP-UX 2 05-06-2011 01:03 PM
If(Condition) Rename a file with (Date+Time) Stamp atechcorp Shell Programming and Scripting 7 02-16-2011 11:08 AM
Rename files bishoo Shell Programming and Scripting 6 05-30-2010 05:19 PM
need help with rename farhan_t49 UNIX for Dummies Questions & Answers 8 05-24-2009 08:40 PM
Solaris 10 ld.so.1 rename alberto Solaris 2 05-22-2009 01:57 PM
Rename fail cv313x Shell Programming and Scripting 12 04-06-2009 04:31 AM
rename bohoo Shell Programming and Scripting 1 04-07-2008 03:05 PM
rename files help piltrafa UNIX for Dummies Questions & Answers 2 10-04-2007 09:47 AM
rename many files fsmadi Solaris 4 04-30-2007 11:27 AM
how can I rename the following=-^ nj78 UNIX for Dummies Questions & Answers 5 09-30-2005 01:13 AM
rename using mv ? simon2000 UNIX for Dummies Questions & Answers 2 03-19-2004 03:46 AM