Для прямого обращения к 4-му столбцу используйте следующийawk
подход:
awk '{ sub(/^POS.*GINFO=/, "", $4) }1' file > new_file
$4
-указывает на 4-е поле sub(/^POS.*GINFO=/, "", $4)
-заменяет подстроку, заданную шаблоном /^POS.*GINFO=
, в 4-м поле После некоторой работы и вдохновения я решил свою проблему:
# dextract-like pushd -- push $1'st directory to top of stack and shift rest down
function pushd {
local t
if [[ $1 =~ ^[-+]?[0-9]+$ ]]; then
pos=$1
[[ ${pos} -lt 0 ]] && ((pos=${#DIRSTACK[@]}+${pos}))
if [[ ${pos} -gt 0 && ${pos} -lt ${#DIRSTACK[@]} ]]; then
t="${DIRSTACK[$pos]}"
# This is crufty. You can't put ~ in DIRSTACK, except the
# shell will put it into position zero when it refers to your
# own directory (not anyone else's!). So replace any occurrences.
DIRSTACK=("" "${DIRSTACK[0]/#~/${HOME}}" "${DIRSTACK[@]:1:${pos}-1}" "${DIRSTACK[@]:${pos}+1}")
cd "$t"
builtin dirs -v
else
echo "$0: pushd: $1: directory stack index out of range" 1>&2
fi
else
builtin pushd "$@" >/dev/null || return
cd.
builtin dirs -v
fi
}