简体   繁体   中英

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).

Is there a method to do this in a linux (or Windows) script, perhaps using an if then statement?

在Linux中,使用uniq命令和-f参数跳过对前两个字段的比较: uniq -f 2 <your-file>

Create a awk script called removeDup.awk as

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM