You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shell脚本实现Autosys Jil转CSV:解决重复参数与分隔符问题

Autosys Jil脚本转CSV文件的优化需求

需求说明

编写Shell脚本,从URL https://jildesctiption:instance/file.txt 获取Autosys Jil脚本并转换为CSV文件,需注意部分作业存在重复参数(例如somejob2中两次定义了envvars)。

示例Jil脚本

/* ----------------- somejob ----------------- */ 

insert_job: somejob   job_type: CMD 
command: SAS ${AUTO_ROOT}/pgms/somejob.sas
machine: someserver.com
owner: user1
permission: gx,wx
date_conditions: 1
run_calendar: 1st_bus_dom
start_times: "07:00"
condition: s(someotherjob)
description: "Send email notification."
std_out_file: "${AUTO_JOB_LOG}.out"
std_err_file: "${AUTO_JOB_LOG}.err"
alarm_if_fail: 1
profile: "/foo/bar/etc/app1"
alarm_if_terminated: 1
timezone: CST6CDT
group: grp1
application: app1
envvars: autojob:python 
resources: (someresource,QUANTITY=2,FREE=A)

/* ----------------- somejob2 ---------------- */ 

insert_job: somejob2   job_type: CMD 
command: SAS ${AUTO_ROOT}/pgms/somejob2.sas
machine: someserver.com
owner: user1
permission: gx,wx
date_conditions: 1
run_calendar: 1st_bus_dom
start_times: "07:00"
condition: s(someotherjob)
description: "Send email notification": AFDG"
std_out_file: "${AUTO_JOB_LOG}.out"
std_err_file: "${AUTO_JOB_LOG}.err"
alarm_if_fail: 1
envvars: abc
envvars: qph
profile: "/foo/bar/etc/app1"
alarm_if_terminated: 1
timezone: CST6CDT
group: grp1
application: app1
resources: (someresource,QUANTITY=2,FREE=A)

已尝试的Shell脚本

#!/bin/sh

curl -L https://jildesctiption:instance/file.txt > File1.txt

sed -i -e '/description: ""/s/: /- /2' File1.txt    
sed 's/ \(job_type:\)/\ \1/' File1.txt  | sed -e 's/^[\t]*//' |
awk -F ': ' 'BEGIN {
 h="insert_job;owner;envvars; description; application;profile"; print h; 
n=split(h,F,/;/)
}
function pr() {
   if (F[1] in A) 
     (for(i=1;i<=n;i++)printf "%s%s", A[F[i]],(i<n)?"^":RS
   }
}
/insert_job/ {pr(); delete A}
# (  # typo?
  for(i in F) {
  if ($0~"^"F[i])A[F[i]]=$2}
 }
END {pr()}' > Jiltoexcel.xls

遇到的问题

  • 由于Jil参数与值使用:分隔,当前脚本用^作为列分隔符,导入Excel时需要手动拆分列;
  • 重复的envvars参数仅保留最后一个值,无法完整展示所有参数值。

内容的提问来源于stack exchange,提问作者MayaDas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 12:57:10