作为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中编写这段代码,以便我可以删除执行此操作并将结果复制回Unix的依赖性。 我可以将文件放在Unix中,如:
Input|Datatype|Target
abc|string|abc
gbf|decimal|gbf
我正在尝试将输出文件作为:
out.abc::in.abc
out.gbf::(deicmal(""))in.gbf
请不要太了解Shell脚本
答案 0 :(得分: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;