English 中文(简体)
采取无序名单作为理由的混合指挥
原标题:Unix cut command taking an unordered list as arguments
  • 时间:2010-08-05 05:51:22
  •  标签:
  • unix
  • shell

Unix cut/code> 指挥权包括一个领域清单,但不是我所需要的命令。

$ echo 1,2,3,4,5,6 | cut -d, -f 1,2,3,5
1,2,3,5

$ echo 1,2,3,4,5,6 | cut -d, -f 1,3,2,5
1,2,3,5

然而,我要按照我具体规定的顺序,向我提供的“九星”指挥。

问题回答

使用:

pax> echo 1,2,3,4,5,6 | awk -F,  BEGIN {OFS=","}{print $1,$3,$2,$5} 
1,3,2,5

pax> echo 1,2,3,4,5,6 | awk -F, -vOFS=,  {print $1,$3,$2,$5} 
1,3,2,5

或者仅仅使用炮弹

$ set -f
$ string="1,2,3,4,5"
$ IFS=","
$ set -- $string
$ echo $1 $3 $2 $5
1 3 2 5

以家庭为基础的解决办法是有害的。 这里的解决办法是:

echo 1,2,3,4,5,6 | perl -e  @order=(1,3,2,5);@a=split/,/,<>;for(@order){print $a[$_-1];} 




相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......