Unix/Linux Go Back    


Emergency UNIX and Linux Support Please post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply.

Rename with a different condition

Emergency UNIX and Linux Support


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-21-2016   -   Original Discussion by jacobs.smith
jacobs.smith jacobs.smith is offline
Banned
 
Join Date: Jan 2012
Last Activity: 24 June 2017, 6:25 PM EDT
Posts: 363
Thanks: 318
Thanked 7 Times in 7 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 11-21-2016   -   Original Discussion by jacobs.smith
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 November 2017, 2:02 AM EST
Location: San Jose, CA, USA
Posts: 10,675
Thanks: 572
Thanked 3,738 Times in 3,190 Posts
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?
Sponsored Links
    #3  
Old Unix and Linux 11-21-2016   -   Original Discussion by jacobs.smith
jacobs.smith jacobs.smith is offline
Banned
 
Join Date: Jan 2012
Last Activity: 24 June 2017, 6:25 PM EDT
Posts: 363
Thanks: 318
Thanked 7 Times in 7 Posts
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 Unix and Linux 11-21-2016   -   Original Discussion by jacobs.smith
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 November 2017, 2:02 AM EST
Location: San Jose, CA, USA
Posts: 10,675
Thanks: 572
Thanked 3,738 Times in 3,190 Posts
Quote:
Originally Posted by jacobs.smith View Post
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:
Rename with a different condition 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.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If condition return 0 even when it fails to satisfy te condition Priya Amaresh Shell Programming and Scripting 2 05-10-2013 02:54 AM
redirect stdout echo command in condition A run in condition B jao_madn Shell Programming and Scripting 3 11-02-2011 10:01 PM
Difference between [condition] and [[condition]] and ((condition)) when used with if condition soumyabubun HP-UX 2 05-06-2011 02:03 PM
If(Condition) Rename a file with (Date+Time) Stamp atechcorp Shell Programming and Scripting 7 02-16-2011 12:08 PM
rename using mv ? simon2000 UNIX for Dummies Questions & Answers 2 03-19-2004 04:46 AM



All times are GMT -4. The time now is 03:43 AM.