简体   繁体   中英

How to insert multi-line output of AWK to Array in UNIX

I made the following work on Linux (RHEL 6.x/7.x), however, there are Unix servers too running HP-UX (B.11.23/B.11.31).

My target isn't to make the same block to work for both envs, I can enforce them to run separately based on OS. But need to perform the following.

Please help me out finding an easy way to do the following on Unix.

#
/u01/app/oracle
/u02/app/oracle
/u03/app/oracle
#

O/P ::

 /u01/app/oracle /u02/app/oracle /u03/app/oracle 
#

I want to get the same thing above done in Unix too. Problem is, there is no way I could find how to insert multiline awk output into an array at one shot like that is possible in RHEL.

I have found a way to do this, good thing it works both with Linux and Unix.

countArr=0
for i in $ABC; do array[$countArr]=$i; countArr=$((countArr+1)); done
for i in "${array[@]}"; do echo $i; done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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