×
UNIX.COM Login
Username:
Password:  
Show Password






👤


UNIX for Beginners Questions & Answers

If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Remove footer record in specific condition

unix, unix & linux - unix commands, unix shell scripting

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-11-2017
KK230689 KK230689 is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 11 July 2018, 3:06 AM EDT
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
Remove footer record in specific condition

Hi Experts,

we have a requirement , need your help to remove the footer record in the file.

Input file :

Code:
1011070375,,21,,NG,NG,asdfsfadf,1011,,30/09/2017,ACI,USD,,0.28,,,,,,,,,,,,
1011070381,,21,,NG,NG,sgfseasdf,1011,,30/09/2017,ACI,GBP,,0.22,,,,,,,,,,,,
1011070389,,21,,NG,NG,werwfsafds,1011,,30/09/2017,ACI,USD,,0.63,,,,,,,,,,,,
1011070389,,21,,NG,NG,safsdgfe,1011,,30/09/2017,ACI,EUR,,0.63,,,,,,,,,,,,
1011070456,,94,,GB,GB,sfsdsa,1011,,31/10/2017,ACI,GBP,,0.55,,,,,,,,,,,,
JE,11-01-2017/05:38,26504


The above highlighted record needs to remove in the file
instead of "JE", some other values also will come. so start with "JE" will fails to convert dynamically.

Thanks in advance

Moderator's Comments:
Remove footer record in specific condition Please post in the appropriate forum

Moderator's Comments:
Remove footer record in specific condition Please use code tags

Last edited by Scrutinizer; 12-11-2017 at 01:47 AM.. Reason: code tags
Sponsored Links
    #2  
Old 12-11-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 7:22 PM EDT
Location: San Jose, CA, USA
Posts: 11,407
Thanks: 649
Thanked 3,970 Times in 3,393 Posts
Please re-read the forum rules you agreed to when you joined this forum. Continued refusal to follow the rules may lead to be placed in read-only mode or in being banned from the UNIX & Linux Forums.

If values other than JE are at the start of records that need to be removed, how are those records identified?

Do you always want to remove every line that starts with a J?

Do you always want to remove every line that starts with an uppercase alphabetic character?

Do you always want to remove every line that starts with a character that is not a numeric character?

Do you always want to remove the last line in every file you process?

Do you always want to remove every line that contains exactly two commas?

What operating system are you using?

What shell are you using?

What have you tried to solve this problem on your own?
Sponsored Links
    #3  
Old 12-11-2017
KK230689 KK230689 is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 11 July 2018, 3:06 AM EDT
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Don Cragun View Post
Please re-read the forum rules you agreed to when you joined this forum. Continued refusal to follow the rules may lead to be placed in read-only mode or in being banned from the UNIX & Linux Forums.

If values other than JE are at the start of records that need to be removed, how are those records identified?

Do you always want to remove every line that starts with a J?

Do you always want to remove every line that starts with an uppercase alphabetic character?

Do you always want to remove every line that starts with a character that is not a numeric character?

Do you always want to remove the last line in every file you process?

Do you always want to remove every line that contains exactly two commas?

What operating system are you using?

What shell are you using?

What have you tried to solve this problem on your own?
we are using the following version of os version

Code:
Linux uklvaucup01a 2.6.32-696.3.2.el6.x86_64 #1 SMP Wed Jun 7 11:51:39 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux

Your question :
Do you always want to remove every line that contains exactly two commas?

Yes , but need not look all line for 2 commas, usual it will be found at the footer record. these record will not be available start and middle. so our approach is to look tail of the file and matches the pattern as less than 2 or 3 commas .

thanks for your quick response

Last edited by rbatte1; 12-11-2017 at 10:27 AM.. Reason: Added CODE tags and fixed some spelling issues
    #4  
Old 12-11-2017
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 3:29 PM EDT
Location: Aachen, Germany
Posts: 13,065
Thanks: 449
Thanked 4,013 Times in 3,690 Posts
What about the other questions that Don Cragun asked, to help you give people in here a decent specification?

Last edited by RudiC; 12-11-2017 at 07:17 AM..
Sponsored Links
    #5  
Old 12-11-2017
KK230689 KK230689 is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 11 July 2018, 3:06 AM EDT
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
If values other than JE are at the start of records that need to be removed, how are those records identified?

Do you always want to remove every line that starts with a J?
No, we need to remove footer record which contains comma less than 3 count
Do you always want to remove every line that starts with an uppercase alphabetic character?
No
Do you always want to remove every line that starts with a character that is not a numeric character?
No
Do you always want to remove the last line in every file you process?
No, because some times they are not giving footer record.in such case the actual value get removed.
Do you always want to remove every line that contains exactly two commas?
Yes. but we can apply the condition as less than 3 counts of comma.
What operating system are you using?

Linux uklvaucup01a 2.6.32-696.3.2.el6.x86_64 #1 SMP Wed Jun 7 11:51:39 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
What shell are you using?

Linux uklvaucup01a 2.6.32-696.3.2.el6.x86_64 #1 SMP Wed Jun 7 11:51:39 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
What have you tried to solve this problem on your own?
sorry i haven't any idea to solve this issue.
Sponsored Links
    #6  
Old 12-11-2017
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 3:29 PM EDT
Location: Aachen, Germany
Posts: 13,065
Thanks: 449
Thanked 4,013 Times in 3,690 Posts
How about
Code:
sed -r '$ {s/^([^,]*,){,2}[^,]*$//;T;d;} ' file

Sponsored Links
    #7  
Old 12-11-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 7:22 PM EDT
Location: San Jose, CA, USA
Posts: 11,407
Thanks: 649
Thanked 3,970 Times in 3,393 Posts
You could also try:
Code:
awk -F, 'NF>3' file

Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[solved] how to remove header and footer ment0smintz Programming 0 09-24-2012 03:08 AM
Add header and footer with record count in footer itsranjan Shell Programming and Scripting 1 03-24-2012 11:45 PM
remove the header and footer using sed vmachava UNIX for Dummies Questions & Answers 8 12-28-2011 12:02 PM
Need to Chop Header and Footer record from input file coolbudy Shell Programming and Scripting 4 08-09-2005 12:26 PM



All times are GMT -4. The time now is 09:21 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.