作为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脚本
如果您的输入文件输入。埃因霍温包含:
Input|Datatype|Target
abc|string|abc
gbf|decimal|gbf
可以使用脚本转换。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*Inputs*|s*Datatypes*|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;