輸入文件:如何把所有號碼字前面殼
new12
abc34
none44
bore93
this67
輸出應該是:
12new
34abc
44none
93bore
67this
如何使用命令做在Unix shell腳本?
輸入文件:如何把所有號碼字前面殼
new12
abc34
none44
bore93
this67
輸出應該是:
12new
34abc
44none
93bore
67this
如何使用命令做在Unix shell腳本?
您可以使用sed。
sed 's/^\([^[:digit:]]\+\)\([[:digit:]]\+\)$/\2\1/' file
這裏有一個AWK:
{
w = d = ""
n = split($1, c, "")
for (i = 1; i <= n; i++)
if (c[i] ~ /[[:alpha:]]/)
w = w c[i]
else
d = d c[i]
print d w
}
$ awk -f switch.awk file
12new
34abc
44none
93bore
67this
要以正確的順序打印,這個詞被分成用於構建字,並根據它們是否匹配數量的字符串的字符數組正則表達式[[:alpha:]]
。
只有bash下
#!/bin/bash
switch(){ tail="${var##*[[:digit:]]}"
head="${var%$tail}"
echo -e "in :$var\t out : $tail$head"; }
while read -r var; do
switch "$var"
done <<-_testwords_
12new
34abc
44none
93bore
67this
87ert67ter
ak356ajf43
_testwords_
爲什麼在'12 new'一個空間,沒有空間其他地方? 'qqq12rrr23sss'作爲輸入行會發生什麼? –