perl + shell script + remove all not uniq lines except the first line uniq (FILE NAME) + perl in shell script -
I have the following file, sed
How to delete all FILE NAME the first unique
file name
, for example, need to delete all the FILE NAME
lines from the file except for the first one:
File P> Parameter Name: Blalabla
Target File: 12
Source File: 565
File Name: / dir1 / dir2 / dir3 / di R4 / dir5 / file
Parameter Name: Blubblaza
Target File: 18
Source File: 552
File Name: / dir1 / Dir2 / dir3 / dir4 / dir5 / file
Parameter name: Blalabla
Target file: 14
Source file: 55 9
Traffic file: 134
Source file: 344
Parameter name: Blubblack
Traffic file: 134
/ P>
file name: / DIA / DIB / DICR / DIER / DIE / file
parameter Name: Blubblaza
Target File: 13
Source File: 445
File Name: / DIA / DIB / DICR / DIER / DIE / File
Parameter name: Blubblack
Target file: 13
$ line_count = 0; Open (OLD_FILE, "& lt; $ old_file") or die ("$ old_file can not open."); Open (NEW_FILE, "> $ new_file") or die ("$ new_file can not open."); While (& lt; OLD_FILE & gt;) {chomp ($ _); If ($ _ = ~ / ^ FILE NAME /) {$ line_count ++; If ($ line_count> 1) {Next; }} Print NEW_FILE "$ _ \ n"; ) Close (file);
This matches a pattern on each line of our old file. If the line starts with "file name" and we already match it once, then it does not print these lines even further in our new file.
Comments
Post a Comment