Link to home
Create AccountLog in
Avatar of donpick
donpick

asked on

Help Searching for code using Github - I have searched Experts Exchange and not found any suitable information

My computer operating system is Windows 7 pro .  

I am trying unsuccessfully to find code in Github.  I need help using the search feature.  Yes, I have searched Experts-Exchange first before posting this message.  I guess I just don’t know what key words to enter.

I have to write a program to switch last name, first name to first name, last name.  I am not a coding expert.  I was hoping to find some vbscript code which would perform the task.  I have to deal with all kinds of names.  In the data I have to convert  there are names with 3 elements like:

Joe Jones Hopkins

Then there are people who have just one name.  
And there are people with suffixes like Jr and III .  Example Joe Jones jr.  etc.

Please explain in detail how you would use Github search to find suitable code to do the above.  I would prefer vbscript but Python code would be suitable also.

Or may be there is an Experts-Exchange article which would help.

Thank you for your help.
Avatar of yo_bee
yo_bee
Flag of United States of America image

Is the data just a text file or does it have separates?

Your question lacks details about the data format.
what’s the source format for the last ans first names? is every full name in a single string field?
Avatar of donpick
donpick

ASKER

The names are in a print file.  I have attached a sample print file.  
The conversion program has to be used by ordinary users.  They don’t know anything about programming.
I considered importing all the names into Excel but this company does not use Windows products.  Their office software is produced by LibreOffice.  Libreoffice does not have the convenient programming interface as Excel does.

If they were using Windows products I would write a vbscript to import the names into Excel and then the names could be in separate cells and I could just interrogate the cells to see if there is relevant data.  So if the names were put into cells beginning with column A, then if column A, B , C and D had data in them then I’d know I am dealing a name like
  Hastings Commert Sara Jones  
where the last name is Hastings Commert and the first name is Sara.

But I don’t have the luxury of using Excel.  
My thought was to read each character in the name field, determine when a space occurred and put the information into an array.  Then, if one array row had 4 elements in it then I’d know  this array row contained a complex name like the one above.

What other ideas can you think of to determine how to recognize a last and first name in the file I have uploaded?
Namefile.txt
I assume you want to extract and process the "Customer NAME" column of the report?

You won't find any turnkey solution by searching, because the code needs to be customized for that particular report format. To properly process, you need to filter for the interesting lines or (better) concat two successive lines to unwind the report's line wraps.

My suggestion is to use either VBScript or PowerShell (preferred) - both are part of the OS, and there is no need to update or install anything.
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of donpick

ASKER

Mr.Tsioumpris:   Thank you for your help.  Great idea.
Based on that data sample, the vbscript code isn't going to work..
Now... since the data sample seems to have fixed size fields, then this should work.. BUT.. (huge caveat).. they *must* be fixed size fields, or this will just mangle what you have.. And if they do end up having variable size fields, then segmenting them will be difficult..

$filepath = 'c:\temp\sample.txt'
$OutputFile = 'c:\temp\Updated_Sample.txt'

$OutputData = [System.Collections.ArrayList]::new()

$reader = [System.IO.File]::OpenText($filepath)

while($null -ne ($line = $reader.ReadLine())) {
    if ($line -match '^\s?(\d{6}|\d{5}).*')
    {
        #Data dataline
        $Segment1 = $line.SubString(0,34)
        $Segment2 = $line.SubString(35,16).Trim() #LastName 
        $Segment3 = $line.SubString(51,14).Trim() #First Name
        $Segment4 = $line.SubString(65,1)  #Middle Initial or space
        $Segment5 = $line.SubString(66)

        $NewSegment3 = $Segment3.PadRight(14,' ')
        $NewMiddleSegment = $NewSegment3, $Segment2 -join ''
        $NewMiddleSegment = $NewMiddleSegment.PadRight(31,' ')
        
        $WriteLine = $Segment1, $NewMiddleSegment, $Segment4, $Segment5 -join ''
    }
    else
    {
        $WriteLine = $line
    }
    [void]$OutputData.Add($WriteLine)
}
Set-Content -Path $OutputFile -Value ($OutputData -join "`r`n")

Open in new window


Using your sample data, here is what got output from it:
[RP00151] Recalls                                               Recall List                                         DATE  9/28/2018 
JOHN    LP GRANGER                                                                                                  TIME      11:41 
USER - RENEE                                                                                                        PAGE          1 
====================================================================================================================================
                                                                                                                                    
PAT REM #    DATE     Cust#          Customer NAME                       PHONE #     REMIND #   REMIND NAME                    CS  
====================================================================================================================================
102266   04/01/18    26233        MARIA DEL CARMDEL RIO JAUREGUI      999 999 9999       5     BOX SPRING 2                        0
102271   04/01/18    29172        LUIS          SOTO                  999 999 9999       5     BOX SPRING 2                        0
102272   04/01/18    25671        NAZIR         PAMPLIN               999 999 9999       5     BOX SPRING 2                        0
102273   04/01/18    28392        SEYED         MAHBAZ           A    999 999 9999       5     BOX SPRING 2                        0
102274   04/01/18    28395        IRIS          CIOSI                 999 999 9999       5     BOX SPRING 2                        0
102275   04/01/18    27882        SHERMAN       LIN                   999 999 9999       5     BOX SPRING 2                        0
102276   04/01/18    I11655       VALERIE       FOLEY            E    999 999 9999       5     BOX SPRING 2                        0
102277   04/01/18    28378        ALMA MARIE    HUSO                  999 999 9999       5     BOX SPRING 2                        0
102278   04/01/18    I11610       KELLIE        BLISH            A    999 999 9999       5     BOX SPRING 2                        0
102279   04/01/18    I5550        CAROL         ENGEN            L    999 999 9999       5     BOX SPRING 2                        0
102280   04/01/18    28333        VIDA          MOVAHEDI MOGHADA      999 999 9999       5     BOX SPRING 2                        0
102281   04/01/18    28402        BRANDI        BANKS            N    999 999 9999       5     BOX SPRING 2                        0
102282   04/01/18    23950        MELANIE       HATCH SLINGWINE       999 999 9999       5     BOX SPRING 2                        0
 94382   04/04/18    I12239       JULIANNE      PARSLEY                                  5     BOX SPRING 2                        0
101902   04/01/18    22275        WINI          SEETHARAMAIAHASH      999 999 9999       5     BOX SPRING 2                        0

Open in new window


Just remember.. this is based on fixed size fields, and swapping the first/middle and lastname sections.. If that doesn't meet your requirements, then it'll need to be adjusted.  I'm sure this could be done with vbscript, but that will take some work.  

Coralon