Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update awk.md #590

Merged
merged 1 commit into from
Jul 10, 2024
Merged

Update awk.md #590

merged 1 commit into from
Jul 10, 2024

Conversation

FunKeen
Copy link
Contributor

@FunKeen FunKeen commented Jul 10, 2024

不同的linux版本,运行相同指令会有不同的结果吗?
当我执行以下指令时

awk '/^web/{T=$0;next;}{print T":"t,$0;}' text.txt

运行结果

web01[192.168.2.100]: httpd            ok
web01[192.168.2.100]: tomcat               ok
web01[192.168.2.100]: sendmail               ok
web02[192.168.2.101]: httpd            ok
web02[192.168.2.101]: postfix               ok
web03[192.168.2.102]: mysqld            ok
web03[192.168.2.102]: httpd               ok

结果中的“:”后只有一个空格,也就是说指令中的“,”有效,而它前面的t似乎没什么作用,去掉后再执行,结果也不会发生变化

当我把指令换成

awk '/^web/{T=$0;next;}{print T":\t"$0;}' text.txt

运行结果

web01[192.168.2.100]:   httpd            ok
web01[192.168.2.100]:   tomcat               ok
web01[192.168.2.100]:   sendmail               ok
web02[192.168.2.101]:   httpd            ok
web02[192.168.2.101]:   postfix               ok
web03[192.168.2.102]:   mysqld            ok
web03[192.168.2.102]:   httpd               ok

”:“后有三个空格,为一个制表符

@jaywcjlove jaywcjlove merged commit 0db6aa6 into jaywcjlove:master Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants