开发者

Do a split on Carriage return and create an array in ksh

开发者 https://www.devze.com 2023-04-04 13:05 出处:网络
I would like to do a split based on Carriage return and subsequently create an array. process.txt siebmtshm 30933160 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_30933160

I would like to do a split based on Carriage return and subsequently create an array.

process.txt

siebmtshm 30933160 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_30933160   
siebmtshm 31064248 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_28508402

Output of the array should be:

Array[0] = siebmtshm 30933160 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_30933160   
Array[1] = siebmt开发者_JS百科shm 31064248 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_28508402


This is pretty simple as your process.txt file is already, technically, split.

You would just have to read the file, line by line, like this:

let tempInt=0
while read file
do
  Array[$tempInt]=$file
  let tempInt=$tempInt+1
done<process.txt

Added a counter in there to keep track of your index within the array. I've done this MANY times in production jobs with no fail. Mind you, just make sure you're using BASH as your interpreter. You wouldn't want to be stuck in the 4096 byte limit the older KSH has.

0

精彩评论

暂无评论...
验证码 换一张
取 消