AWK中的字符串比较 [英] String comparison in awk

查看:496
本文介绍了AWK中的字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要按字母顺序比较两个字符串,而不仅仅是相等性测试.我想知道是否可以在awk中进行字符串比较?

I need to compare two strings in alphabetic order, not only equality test. I want to know is there way to do string comparison in awk?

推荐答案

确定可以:

pax$ echo 'hello
goodbye' | gawk '{if ($0 == "hello") {print "HELLO"}}'
HELLO

您还可以进行不等式(有序)测试:

You can also do inequality (ordered) testing as well:

pax> printf 'aaa\naab\naac\naad\n' | gawk '{if ($1 < "aac"){print}}'
aaa
aab

这篇关于AWK中的字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆