简体   繁体   English

在Shell脚本中处理多行变量

[英]Processing multiline variable in shell script

I have extracted the results of a query in a variable. 我已将查询的结果提取到变量中。

echo "$a"
TABLESPACE_NAME                  TOT_SIZE   PCT_FREE    DATAFILE
------------------------------ ---------- ----------    -----------
SYSTEM                               1000     40.625    /u01/oracle/datafile1.dbf
SYSAUX                               1000    67.2375    /u01/oracle/datafile2.dbf
USERS                                  55 96.3636364    /u01/oracle/datafile3.dbf
UNDOTBS1                             1000    98.0625    /u01/oracle/datafile4.dbf

I need to check the location of datafile ( /u01/oracle ) for space ,then add a datafile for each tablespace. 我需要检查数据文件( /u01/oracle )的空间,然后为每个表空间添加一个数据文件。

Basically what im trying to do is :- 我基本上想做的是:-

 loop
 extract location from 4th col
 check for space availability

could you please suggest how to proceed. 您能否建议如何进行。

You can use this simple awk command to print 1st and last columns for each row for the row # greater than two: 您可以使用此简单的awk命令为行号大于2的每一行打印第一列和最后一列:

echo "$a" | awk 'NR>2 {printf "Table space name: %s and datafile name: %s\n", $1, $NF}'

This will print table name and datafile for each record. 这将为每个记录打印表名和数据文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM