23,120
社区成员
发帖
与我相关
我的任务
分享
name age sex wage
liu 25 male 3456
zhang 27 female 4567
name age sex wage
ma 26 male 3856
sun 26 female 4667
#!/bin/sh
parse()
{
echo $file |tee -a parsed
awk -v cols="$args" '
BEGIN {
}
NR==1 {
for (i=1;i<=NF;i++) {
if (index(cols, $i) > 0)
field[i]=$i
}
}
{
for (i in field)
printf ("%s \t", $i)
printf("\n")
}' $file
}
args=$*
if echo $args | grep -q " *[0-9][0-9] *$"; then
file=${args%% *}
time=${args##* }
args=${args#* }
args=${args% *}
for file in $(ls); do
f2=$(echo $file|awk -F[._] '{print $2}')
f4=$(echo $file|awk -F[._] '{print $4}')
echo $f2 | grep -q "^[0-9][0-9]$" || continue
echo $f4 | grep -q "^[0-9][0-9]$" || continue
if [ $f2 -lt $time -a $f4 -lt $time ]; then
if ! grep -q "$file" parsed; then
parse |tee -a result
fi
fi
done
else
file=${args%% *}
args=${args#* }
if ! grep -q "$file" parsed; then
parse |tee -a result
fi
fi
# ./parse.sh D20120208.05_20120208.06_DAA name sex 10
D20120208.05_20120208.06_DAA
name sex
liu male
zhang female
D20120208.08_20120208.09_DAA
name sex
ma male
sun female