Home Man
Search
Today's Posts
Register

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

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

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 12-11-2017
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
# 2  
Old 12-11-2017
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?
# 3  
Old 12-11-2017
Quote:
Originally Posted by Don Cragun
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
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..
# 5  
Old 12-11-2017
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.
# 6  
Old 12-11-2017
How about
Code:
sed -r '$ {s/^([^,]*,){,2}[^,]*$//;T;d;} ' file

# 7  
Old 12-11-2017
You could also try:
Code:
awk -F, 'NF>3' file

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
sed substitution for specific record somersetdan Shell Programming and Scripting 5 05-21-2012 12:32 PM
[AWK script]Counting the character in record and print them in condition Antonlee Shell Programming and Scripting 1 04-03-2012 07:47 AM
Add header and footer with record count in footer itsranjan Shell Programming and Scripting 1 03-24-2012 11:45 PM
Grab unique record from different files on a condition jacobs.smith Shell Programming and Scripting 6 02-08-2012 02:29 PM
remove the header and footer using sed vmachava UNIX for Dummies Questions & Answers 8 12-28-2011 12:02 PM
Help with File processing - Adding predefined text to particular record based on condition karumudi7 Shell Programming and Scripting 8 10-14-2011 01:02 PM
Remove the footer from a flat file by searching a pattern gani_85 Shell Programming and Scripting 6 10-03-2011 02:05 AM
remove header and footer rows seaky Shell Programming and Scripting 2 11-10-2006 10:18 AM
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 03:20 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password