I have a auto generated test file that had a username that combines first letter of first name with last name and part of an ID number. The problem I am having is if someone has a last name of two or more words it puts a space in that kills my automated upload. Here is part of the data:
"ACC",250123,"John","Doe","MS","jdoe123"
"ACC",250124,"Jennifer","Smith","AH","jsmith124"
"ACC",250125,"Earl","Van Little","AH","evan little125"
"ACC",250126,"Joe","Sori","MS","jsori384"
"ACC",250127,"Betsy","Homal","HU","bhomal127
I have tried writing a batch file script that removes the space in Earl's username (last field) above but the best I can do is cut off from the letter 'n' on.
Any ideas?
thanks!
Bob
Need help removing spaces
Moderator: DosItHelp
Re: Need help removing spaces
Do you only want to change the text file, in the final term? Test this on file.txt
This uses a helper batch file called `Jrepl.bat` (by dbenham) - download from: https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat
Place `Jrepl.bat` in the same folder as the batch file or in a folder that is on the path.
Code: Select all
jrepl "(.*,.*) (.*)" "$1$2" /f file.txt /o -
This uses a helper batch file called `Jrepl.bat` (by dbenham) - download from: https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat
Place `Jrepl.bat` in the same folder as the batch file or in a folder that is on the path.
Re: Need help removing spaces
That will remove at most one space from the username field. That may not be enough. My solution below uses a negative lookahead. It removes a space if after the space there does not exist a string of characters, followed by a quote, followed by another character.
If you are starting with text that looks like:
Then the following will append the correct usernames in one step:
Dave Benham
Code: Select all
jrepl " (?!.*?\q.)" "" /x /f test.txt /o -
If you are starting with text that looks like:
Code: Select all
"ACC",250123,"John","Doe","MS"
"ACC",250124,"Jennifer","Smith","AH"
"ACC",250125,"Billy Ray","Van Little","AH"
"ACC",250126,"Joe","Sori","MS"
"ACC",250127,"Betsy","Homal","HU"
Then the following will append the correct usernames in one step:
Code: Select all
jrepl ".*?,\d*(\d{3}),\q(.).*?\q,\q(.*?)\q.*" "$0+',\x22'+($2+$3.replace(/ /g,'')+$1).toLowerCase()+'\x22'" /x /j /f test.txt /o out.txt
Dave Benham
Re: Need help removing spaces
Thanks everyone. I really appreciate your help. The code seems to work except it added another user (and remove the space) at the end. How do I make it just replace the user? I only need the one username on the end.
Code: Select all
"ACC",250123,"John","Doe","MS","jdoe123","jdoe123"
"ACC",250124,"Jennifer","Smith","AH","jsmith124","jsmith124"
"ACC",250125,"Earl","Van Little","AH","evan little125","evanlittle125"
"ACC",250126,"Joe","Sori","MS","jsori384","jsori126"
"ACC",250127,"Betsy","Homal","HU","bhomal127,"bhomal127"
Re: Need help removing spaces
After re-re-reading the post, I am not sure I explained the problem throughly. The text file is auto generated by our old system with the user already included in the file. I can't have it re-create the user unless I somehow strip it off the end. That's why I thought the easiest way was just to remove the space.
I guess that's why I am getting double now. Thanks again for all your help.
Bob
I guess that's why I am getting double now. Thanks again for all your help.
Bob
Re: Need help removing spaces
If your source already has the username, then disregard my second solution. Just use the one liner at the top.
Dave Benham
Dave Benham
Re: Need help removing spaces
Thanks Dave, that worked perfectly. I appreciate all your help.