#1 08 Mar 2016 11:21

ravi_majji
Member
Registered: 27 Jul 2011
Posts: 13

Hi all , i need your help, i need to convert VB 2 Sheel

Hi Friends,

I have a requirement and I am just newbee in shell scripting, we have a vbscript which will validate a incoming file , now we need to convert this VB script to Shell script as our servers are migrated to EXALYTICS.

so I need your help in converting the below VB code to Shell..

================

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, Source, Target, InputName, OutputName, TextLine, vErrorCount, LineCount
Dim Params
Const FX_RATE_NAME = 0, FX_USD_CURR = 1, FX_RATE_MONTH = 2, FX_RATE_YEAR = 3, FX_RATE_VALUE = 4, FX_RATE_EURO = 5, FX_RATE_TYPE = 6

Set fso = CreateObject("Scripting.FileSystemObject")

' Open the file for reading.

InputName = "E:\FX_RATES\OUT\mor.csv"

Dim objStream, strData
Set objStream = CreateObject("ADODB.Stream")

Set Source = fso.OpenTextFile(InputName, ForReading)

objStream.CharSet = "utf-8"
objStream.Open

vErrorCount = 0
LineCount = 0

' Read from the file and validate line by line
Do While Source.AtEndOfStream <> True

    validFlag = True

    TextLine = Source.ReadLine

    LineCount = LineCount + 1

    Params = Split(TextLine, ",")

    ParamCount = Len(TextLine) - Len(Replace(TextLine, ",", ""))

    If ParamCount = 6 Then

        If Len(Params(FX_RATE_NAME)) <> 3 Then
            objStream.WriteText "Invalid currency code " & Params(FX_RATE_NAME) & vbCrLf
            validFlag = false
        End If

        If Len(Params(FX_USD_CURR)) <> 3 Then
            objStream.WriteText "Invalid conversion code " & Params(FX_USD_CURR) & vbCrLf
            validFlag = false
        End If

'Or CInt(Params(FX_RATE_MONTH)) <> Month(Now)

'        If IsNumeric(Params(FX_RATE_MONTH)) Then
'            If CInt(Params(FX_RATE_MONTH)) <> Month(DateAdd("d", 16, Now))  Then
'                objStream.WriteText "Invalid month " & Params(FX_RATE_MONTH) & " should be " & Month(DateAdd("d", 16, Now)) & vbCrLf
'                validFlag = false
'            End If
'        Else
'            objStream.WriteText "Invalid month " & Params(FX_RATE_MONTH) & vbCrLf
'            validFlag = false
'        End If

        If IsNumeric(Params(FX_RATE_YEAR)) Then
            If CInt(Params(FX_RATE_YEAR)) <> Year(DateAdd("d", 16, Now)) Then
                objStream.WriteText "Invalid Year " & Params(FX_RATE_YEAR) & " should be " & Year(DateAdd("d", 16, Now)) & vbCrLf
                validFlag = false
            End If
        Else
            objStream.WriteText "Invalid Year " & Params(FX_RATE_YEAR) & vbCrLf
            validFlag = false
        End If

        If Not IsNumeric(Params(FX_RATE_VALUE)) Then
            objStream.WriteText "Invalid conversion rate " & Params(FX_RATE_VALUE) & vbCrLf
            validFlag = false
        End If

        If UCase(Params(FX_RATE_TYPE)) <> "M" Then
            objStream.WriteText "Invalid Rate Type " & Params(FX_RATE_TYPE) & vbCrLf
            validFlag = false
        End If

    Else
        objStream.WriteText "Invalid file format "
        validFlag = false
    End If

    If validFlag = False Then
        objStream.WriteText TextLine & vbCrLf & "-----------------------------------------------------------------" & vbCrLf
        vErrorCount = vErrorCount + 1
    End If

Loop

'if file has only one line.... write as File invalid...

If LineCount < 2 Then
    objStream.WriteText "File too short.. Invalid "
    vErrorCount = 1
End If


If vErrorCount > 0 Then
    objStream.SaveToFile "E:\FX_Rates\Mor_Errors.csv", 2
End If

objStream.Close

Source.Close

================================================
the above code has to converted to shell .. I am badly struck here .. pls help.

below are the few lines in the source file ( file is CSV file )

ADP    USD    4    2015    0.0065925    166.386    G
DZD    USD    4    2015    0.0093673        G
AFN    USD    4    2015    0.01514        G
ALL    USD    4    2015    0.0079475        G
AOA    USD    4    2015    0.0073907        G
ARS    USD    4    2015    0.0720981        G
AWG    USD    4    2015    0.5555556        G
AUD    USD    4    2015    0.72185        G
ATS    USD    4    2015    0.0797148    13.7603    G

** I had given the file data for GAP rates file, but the VB example is with MOR rates file

Last edited by ravi_majji (08 Mar 2016 13:16)

Offline

Board footer

Powered by FluxBB