Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我做
awk -F: '{print $1}' /etc/passwd
然后我得到所有的用户名。
问题
是否有可能只输出 4 个字符长的 awk?
使用长度函数:
awk -F: 'length($1)==4{print $1}' /etc/passwd
尝试
awk -F: '( $1 ~ /^....$/ ){print $1}' /etc/passwd
perl -F -lane 'print $F[0] if(length($F[0])==4)' /etc/passwd