shell脚本之awk实现的tac

发布时间:2020-02-11编辑:脚本学堂
shell脚本之awk实现的tac,有需要的朋友可以看看。# awk '{a[NR]=$0}END{for (i=NR;i>=1;i--)print a[i]}' file

shell/ target=_blank class=infotextkey>shell脚本linuxjishu/13830.html target=_blank class=infotextkey>awk实现的tac,有需要的朋友可以看看。
# awk '{a[NR]=$0}END{for (i=NR;i>=1;i--)print a[i]}' file

[root@station1 ~]# cat file
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
pulse:x:496:494:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
tom:x:500:500:tom:/home/tom:/bin/bash

[root@station1 ~]# awk '{a[NR]=$0}END{for (i=NR;i>=1;i--)print a[i]}' file
tom:x:500:500:tom:/home/tom:/bin/bash
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:496:494:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin