我在这里相当新,并希望了解有关bash编程的更多信息。
首先,我需要一些finger命令的帮助。 当我使用“手指”这就是我得到的输出,显然有一些数据集。
Login Name Tty Idle Login Time Where
我想要的是,我调整了finger命令,因此它只输出带有相关数据集的“Name”,如:
Name
...
答案 0 :(得分:1)
您可以使用finger | awk '{print $2}'
:
awk
编辑:使用cut
和#!/bin/bash
#parse_finger.sh
#Read first line from stdin
IFS='$\n' read -r line
#Count the number of chars until 'Name'
str=$(echo "$line" | awk -F "Name" '{print $1}')
start=${#str}
start=$((start+1))
#Count the number of chars until 'Tty'
str=$(echo "$line" | awk -F "Tty" '{print $1}')
stop=${#str}
stop=$((stop-1))
#Print out the 'Name' header
echo "$line" | cut -c $start-$stop
#Read in the rest of our lines and print the cols we care about
while IFS='$\n' read -r line; do
echo "$line" | cut -c $start-$stop
done
组合的新方法,对于任意格式化的名称更为强大。
finger | parse_finger.sh
使用vars