Delete duplicate second line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete duplicate second line
# 1  
Old 07-08-2011
Delete duplicate second line

Hi ALL

I need a help

I need to retain only the first line of 035 if I have two line before =040 , if only one then need to take that

Eg:

Input
Code:
=035      (ABC)12324141241
=035      (XYZPQR)704124
=040       AB$QS$WEWR
=035      (ABC)08080880809
=035      (XYZPQR)9809314
=040       OUSOI$NLLNL$
=035       (ABC)0498318414
=040       OUSOI$NLLNL$

Output

Code:
=035      (ABC)12324141241
=035      (ABC)08080880809
=035       (ABC)0498318414

Please help
Thanks a lot for ur time

Regards

Last edited by pludi; 07-08-2011 at 03:36 AM..
# 2  
Old 07-08-2011
Try this:
Code:
awk '/=035/ && !s{s=$0} /=040/{print s; s=""}' file

# 3  
Old 07-08-2011
perfect, thanks a ton

---------- Post updated at 03:46 PM ---------- Previous update was at 03:10 PM ----------

oh no, i think if it is single 035 then its ignoring. Please help me to check
# 4  
Old 07-08-2011
It works with the given samples of your first post. Can you post an example where it goes wrong?
# 5  
Old 07-13-2011
Bug I would like to share my simple idea for this request.

Please try the below.

Asssume your input file name is test.

Step1: Replace the newline character with _
Code:
perl -p -i.bak1 -e 's/\n/_/g' test

Step2: Finding the required pattern and ignore printing the second 035 record
Code:
perl -p -i.bak2 -e 's/(=[0-9]{3} +\([a-zA-Z]+\)[0-9]+_)(=[0-9]{3} +\([a-zA-Z]+\)[0-9]+_)(=040[^_]+)/$1$3/g' test

Step3: Replacing the _ with newline character
Code:
perl -p -i.bak3 -e 's/_/\n/g' test

Step4: Removing the 040 records from the file
Code:
perl -i.bak4 -ne 'print unless /^=040/' test


I could not improve this four commands into a single command, if anyone knows how to write this in a single command please post the same.

Thanks,
Chidhu.Anu

Last edited by Franklin52; 07-13-2011 at 04:46 AM.. Reason: Please use code tags for code and data samples, thank you
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

2. Shell Programming and Scripting

Delete duplicate directories?

Is there a way via some bash script or just cmd to find duplicate directories? i have main folders: TEST1 TEST2 In folder TEST1 is some amount of same folders as in folder TEST2 can be this done? i tried fdupe but it only search for dupe files not whle dirs thx! (8 Replies)
Discussion started by: ZerO13
8 Replies

3. UNIX for Dummies Questions & Answers

Log file - Delete duplicate line & keep last date

Hello All ! I need your help on this case, I have a csv file with this: ITEM105;ARI FSR;2016-02-01 08:02;243 ITEM101;ARI FSR;2016-02-01 06:02;240 ITEM032;RNO TLE;2016-02-01 11:03;320 ITEM032;RNO TLE;2016-02-02 05:43;320 ITEM032;RNO TLE;2016-02-01 02:03;320 ITEM032;RNO... (2 Replies)
Discussion started by: vadim-bzh
2 Replies

4. Shell Programming and Scripting

Delete duplicate row

Hi all, how can delete duplicate files in file form, e.g. $cat file1 aaa 123 234 345 456 bbb 345 345 657 568 ccc 345 768 897 456 aaa 123 234 345 456 ddd 786 784 234 263 ccc 345 768 897 456 aaa 123 234 345 456 ccc 345 768 897 456 then i need ouput file1 some, (4 Replies)
Discussion started by: aav1307
4 Replies

5. Shell Programming and Scripting

Delete duplicate strings in a line

Hi, i need help to remove duplicates in my file. The problem is i need to delete one duplicate for each line only. the input file as follows and it is not tab delimited:- The output need to remove 2nd word (in red) that duplicate with 1st word (in blue). Other duplicates should remained... (12 Replies)
Discussion started by: redse171
12 Replies

6. Shell Programming and Scripting

Delete duplicate rows

Hi, This is a followup to my earlier post him mno klm 20 76 . + . klm_mango unix_00000001; alp fdc klm 123 456 . + . klm_mango unix_0000103; her tkr klm 415 439 . + . klm_mango unix_00001043; abc tvr klm 20 76 . + . klm_mango unix_00000001; abc def klm 83 84 . + . klm_mango... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

7. Shell Programming and Scripting

Delete Duplicate line (not really) from the file

I need help in figuring out hoe to delete lines in a data file. The data file is huge. I am currently using "vi" to search and delete the lines - which is cumbersome since it takes lots of time to save that file (due to its huge size). Here is the issue. I have a data file with the following... (4 Replies)
Discussion started by: GosarJunk
4 Replies

8. Shell Programming and Scripting

How to delete a duplicate line and original with sed.

I am completely new to shell scripting but have been assigned the task of creating several batch files to manipulate data. My final task requires me to find lines that have duplicates present then delete not only the duplicate but the original as well. The script will be used in a windows... (9 Replies)
Discussion started by: chino_1
9 Replies

9. Shell Programming and Scripting

Need to delete duplicate lease entry

Hi *, I need to delete duplicate lease entries in file according to MAC/IP. I'm having tempfile which contains many lease info and need to have one entry for each IP(not more than that), if it contains more than one entry for same set, need to be deleted that entry... EX: lease... (4 Replies)
Discussion started by: SMNK
4 Replies

10. UNIX for Advanced & Expert Users

Delete Duplicate Cronjobs

I set up same cronjobs in two different users to generate messages at 5:30 AM Not Its generating duplicate messages. I want to delete the cron entries set up in the first user, but I am unable to view the entries in that user. I tried to find the process Id, but its not showing any id Could... (2 Replies)
Discussion started by: nskworld
2 Replies
Login or Register to Ask a Question