To assign awk array in the array shell

2011-05-26  来源:本站原创  分类:OS  人气:64 

Method 1, through the eval

#!/bin/bash
ipstr="192.168.1.152,192.168.1.153";
#declare -a arr;
eval $(echo $ipstr | awk '{split($0, filearray, ",");for(i in filearray)print "arr["i"]="filearray[i]}')
#eval  The contents of the print , And JavaScript eval The same capabilities
#echo ${arr[1]}
for i in ${arr[*]}
do
#scp_c="scp $i:/opt/flow_video/2011-05-26.txt"
#echo $scp_c
scp $i:/opt/flow_video/2011-05-26.txt /opt/flow_video/2011-05-26_$i.txt
done

Method 2 temporary files by

#!/bin/sh
count=0
str="123#abc#@&?"
`awk 'BEGIN { split("'"$str"'",a,"#")}
     END   { for (i in a) {print a[i];$count++; }}'  /dev/null > 2`

while read buf
do
 tArray[$c]=$buf
 c=$(expr $c + 1)
done < 2
echo "array len:" $c
for((i=0;i<$c;i++));
do
  echo ${tArray[$i]}
done

Execution output
array len: 3
123
abc
@ &?

相关文章
  • bash shell shell array and an array of analog queue queue tips 2011-07-07

    An array of simulated operational shell queue queue or stack stack http://www.tech-recipes.com/rx/911/queue-and-stack-using-array/ here is a series of operation on array, we can use these functions to implement a queue or stack that can help us more

  • php function array_filter () filter php remove empty array of empty array _php 2010-05-15

    Before judging whether the array element is empty, the general use of foreach, because the more specific application is to foreach, in fact, if a simple air filter array php, you can use the php function array_filter (). array array_filter (array [,

  • java object array of Java Array sort sort sort 2010-06-13

    Java collection object sorting test Java API for sorting the collection offers two types of support: java.util.Collections.sort (java.util.List) java.util.Collections.sort (java.util.List, java.util.Comparator) The first method requires the sort of e

  • Realize the value of an integer array of one-dimensional array sort 2011-04-26

    Php function related to a sort of native sort ($ array, SORT_NUMERIC) function array_sort($array) { $return = array(); $no = count($array); $max_key = 0; for($i = 0; $i < $no; $i++) { $tmp=0; foreach ($array as $key => $num) { if($num > $tmp) { $

  • C# string Array to int Array 2014-05-12

    在C#中,目前发现的将"字符串型数组string[]"转换为"整型数组int[]"的最简单方法: string[] ids = new string[5] { "5", "6", "7", "8", "9" };int[] ids2 = Array.ConvertAll(ids, id => Convert.ToInt32(id)); 使用的是Array的静态方

  • Array.slice()与Array.splice()的返回值类型 2014-11-24

    最近做个练习,用到Array.slice()和Array.splice(),以前没有注意其返回值类型 Array.slice()返回Array -- 一个由原始数组中某一范围的元素构成的数组. Array.splice()返回Array -- 包含从原始数组中删除的元素的一个数组. 返回的是一个数组,用typeof()看一下是object,这没错!需要提醒大家的是: 当数组元素是数字时,用Array.slice()和Array.splice()取其中某个元素进行大小比较,可得要注意,必须转换 类

  • To assign awk array in the array shell 2011-05-26

    Method 1, through the eval #!/bin/bash ipstr="192.168.1.152,192.168.1.153"; #declare -a arr; eval $(echo $ipstr | awk '{split($0, filearray, ",");for(i in filearray)print "arr["i"]="filearray[i]}') #eval The content

  • AS 3.0 array sort question: Array.sort () method 2010-04-24

    Quote Sort the array can be used three ways (reverse (), sort () and sortOn ()) reverse () method without parameters or return values, but you can order from the current switch array in reverse order. sort () method in accordance with the "default so

  • java two dimensional array into one-dimensional array 2010-07-31

    java in two-dimensional array can be directly converted into one-dimensional array model: array [n] [2]. public class Shuzu { public static void main(String[] args) { String[][] b = {{ "aa", "bb" },{ "cc", "dd" } };

  • How to traverse a smarty-dimensional array with two-dimensional array 2011-05-13

    (1) one-dimensional array You can use foreach. For example: Array: $ addr = array ( '01 '=>' Guangzhou ', '02 '=>' Shaoguan ' '03 '=>' Shenzhen ', '04 '=>' Zhuhai ' '05 '=>' Shantou ', '06 '=>' Foshan ', '53 '=>' Yunfu ' '52 '=>' J

  • js利用Array.splice实现Array的insert/remove 2014-01-18

    从一个数组中移除一个或多个元素,如果必要,在所移除元素的位置上插入新元素,返回所移除的元素. arrayObj.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]]) 参数 arrayObj 必选项.一个 Array 对象. start 必选项.指定从数组中移除元素的开始位置,这个位置是从 0 开始计算的. deleteCount 必选项.要移除的元素的个数. item1, item2,. . .,itemN 必选项.要在所移

  • awk 实例 睡梦中的shell 2012-11-12

    好吧,趁着鸡血效果还在,抓紧学习 vi text.txt F115!16201!1174113017250745 10.86.96.41 211.140.16.1 200703180718 F125!16202!1174113327151715 10.86.96.42 211.140.16.2 200703180728 F235!16203!1174113737250745 10.86.96.43 211.140.16.3 200703180738 F245!16204!117411384725

  • [Reserved] linux shell to create and use an array of skills 2011-08-17

    Reproduced http://www.cnblogs.com/chengmo/archive/2010/09/30/1839632.html 1 array definition [Chengmo @ centos5 ~] $ a = (1 2 3 4 5) [Chengmo @ centos5 ~] $ echo $ a 1 A pair of parentheses that is an array, the array element with the "space" sy

  • linux shell awk syntax (switch) 2011-05-24

    http://blog.csdn.net/weekly123/archive/2006/12/28/1465675.aspx Awk is a very good language, but there is a very strange name. In this series (a total of three articles), the first article, Daniel Robbins will allow you to quickly master the awk progr

  • SHELL awk 及例子 2013-03-26

    觉得有用请顶一下,谢谢 awk 语言特性 Language Characteristics [[email protected] ~]# cat /etc/passwd | awk 'BEGIN{print "How many people use nologin?"} /nologin/ {++addr} END{print "'nologin' appears " addr " times."}' How many people use nologin

  • JS tutorial - an array of detailed 2009-04-26

    1. Array statement Ways (1): arrayObj = new Array (); / / create an array. var arr1 = new Array(); (2): arrayObj = new Array ([size]) to create an array and specify the length, the attention is not a ceiling, are the length. var a = new Array(5); (3)

  • Second class: array. Object-oriented (1) 2010-05-02

    An array 1, the array is a type 2, the definition of an array 3, the array of initialization: static and dynamic initialization initialization Are two initialization syntax Dynamic initialization, the system assigned default values: byte, short, int

  • Php Learning "1" ------ array 2010-08-03

    1. Array of categories a. the value of the array with an array of keys with a digital ID can use different methods to create a numerical array: Example 1 In this example, will automatically assign ID Key : $names = array("Peter","Quagmire&q

  • Reading new.delete. Point to a continuous space pointer. Array. Space release. Space applications [C + +] [Memory Management] Impression 2010-08-13

    1. Use new and delete operator, the rate of change when the PF Ctrl + Alt + Del to enter the Task Manager, performance, run the following code, and observe the PF rate changes. Known, new operator to increase PF rate, delete to restore the PF rate. N

  • JS Array "(array) and the" objects "(object) 2010-08-24

    JS Array "(array) and the" objects "(object) JS Technology 2009-12-30 16:15:45 read 294 comments 0 font size: large, medium Subscribe For example there is an array a = [1,2,3,4], there is an object a = (0:1,1:2,2:3,3:4), and then you run th