0

As a part of Ab Initio Reformat i need to map input fields to output and covert as per there datatype. I wrote a vba script to automate that. 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

The output is like,

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

I want to write this code in Unix so that i can remove the dependency of going to Windows performing this and copying result back to Unix. I can place file in Unix like:

Input|Datatype|Target

abc|string|abc

gbf|decimal|gbf

And i am trying to get output file as:

out.abc::in.abc

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

Please help not that much aware of Shell scripting

codedude
  • 6,244
  • 14
  • 63
  • 99
Ankit Srivastava
  • 185
  • 3
  • 13

1 Answers1

0

If your input file input.psv contains:

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

you can use a script convert.ksh as such:

#!/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

To do the following:

./convert.ksh ./input.psv
out.abc ::      (string(""))in.abc;
out.gbf ::      (decimal(""))in.gbf;
Alex
  • 95
  • 7