0

作为 Ab Initio Reformat 的一部分,我需要根据数据类型将输入字段映射到输出和隐蔽。我写了一个 vba 脚本来自动化它。PFB

Sub reformat()

Dim sel As String
Dim j As String

sel = ""
Sheet1.Activate
k = Cells(Rows.Count, "A").End(xlUp).Row
MsgBox (k - 1)
For i = 2 To k

If Cells(i, 2).Value = "1" Then
Cells(i, 5).Value = "out." + Cells(i, 1).Value + "::" + "in." + Cells(i, 4).Value
End If
If Cells(i, 2).Value = "Lkp" Then
Cells(i, 5).Value = "out." + Cells(i, 1).Value + "::" + "first_imp(" + Cells(i, 3) + ")." + "in." + Cells(i, 4).Value
End If
If Cells(i, 2).Value = "DT" Then
Cells(i, 5).Value = "out." + Cells(i, 1).Value + "::" + Cells(i, 3) + "in." + Cells(i, 4)
End If
Next i

输出就像,

Input   Datatype    Target  
abc string  abc out.abc::in.abc
gbf decimal gbf out.gbf::(decimal(""))in.gbf

我想在 Unix 中编写此代码,以便我可以消除去 Windows 执行此操作并将结果复制回 Unix 的依赖性。我可以将文件放在 Unix 中,例如:

Input|Datatype|Target

abc|string|abc

gbf|decimal|gbf

我正在尝试将输出文件获取为:

out.abc::in.abc

out.gbf::(deicmal(""))in.gbf

请帮助不太了解Shell脚本

4

1 回答 1

0

如果您的输入文件 input.psv 包含:

Input|Datatype|Target
abc|string|abc
gbf|decimal|gbf

您可以像这样使用脚本 convert.ksh:

#!/usr/bin/ksh

if [[ -z ${1} ]]
then
        echo "";
        echo "Usage:   $0 <pipe delimited file name>";
        echo "Example: $0 file_name.psv";
        echo "";
        exit 1;
fi

for i in $(cat ${1}|grep -vP '^\s*Input\s*\|\s*Datatype\s*\|\s*Target')
do
        echo ${i}|awk -F'|' '{print "out." $1 "\t::\t(" $2 "(\"\"))in." $3 ";"}';
done

执行以下操作:

./convert.ksh ./input.psv
out.abc ::      (string(""))in.abc;
out.gbf ::      (decimal(""))in.gbf;
于 2016-04-22T20:16:44.593 回答