获得在bash某些列 [英] Getting certain columns in bash

查看:136
本文介绍了获得在bash某些列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个数组,数组中的每个元素的格式如下:

Suppose I have an array where each element in the array is in the following format:

someText (x1,y1,z1) (x2,y2,z2) (x3,y2,z3) KEY

什么是建设一个新的数组,其中是新的数组中的元素只有1和previous阵列的最后一列的方法?

What is the approach for building a new array where is element in the new array is only 1st and last column of the previous array?

推荐答案

您可以做这样的事情(其中 OLDARRAY 是previous阵列和 NEWARRAY 是新的)。

You can do something like this (where OLDARRAY is the previous array and NEWARRAY is the new one).

NEWARRAY=()
for I in "${!OLDARRAY[@]}"; do
    IFS=$' ' read -ra T <<< "${OLDARRAY[I]}"
    NEWARRAY[I]="${T[0]} ${T[@]:(-1)}"
done

输出示例:

> set | grep ^NEWARRAY
NEWARRAY=([0]="someText KEY" [1]="someText2 KEY2")

这篇关于获得在bash某些列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆