[英]Need Help Creating Linux Script
I have the following: 我有以下几点:
...
#define DIRT 4
#define PLANKS 5
#define WOOD_PLANKSs 5
#define BRICKS 6
...
I need to remove one of the lines that have the same number as the line before them (Ex. Remove planks because woodplanks has the same number, 5). 我需要删除与前一行编号相同的行之一(例如,删除木板,因为木板的编号相同,为5)。
Is there a method to do this in a linux (or Windows) script, perhaps using an if then statement? 有没有一种方法可以在Linux(或Windows)脚本中执行此操作,也许使用if then语句?
在Linux中,使用uniq
命令和-f
参数跳过对前两个字段的比较: uniq -f 2 <your-file>
Create a awk script called removeDup.awk as 创建一个名为removeDup.awk的awk脚本,如下所示:
1 BEGIN { lastDefine=""
2 }
3 /^#define/ { if (lastDefine=="") {
4 lastDefine=$3
5 } else {
6 if (lastDefine==$3) {
7 next
8 } else {
9 lastDefine=$3
10 }
11 }
12 }
13 { print
14 }
awk -f removeDup.awk filename awk -f removeDup.awk文件名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.