|
Answer» I am completely new to scripting but have been assigned the tasks of creating several batch files to manipulate data. My final task requires me to find lines that have certain duplicates present then delete not only the duplicate but the original as well and strip out the quotes at the same time as shown in the sample below:
"180222","1","8.5","1Z0E947355363450","9.49","UPAC","N" "180223","1","7.3","1Z0E947357325461","6.53","UPAC","N" "180225","1","3.9","1Z0E947355178080","4.77","UPAC","N" "180223","1","7.3","1Z0E947357325461","6.53","UPAC","N" "180222","1","8.5","1Z0E947355363450","9.49","UPAC","Y"
What needs to occur is when a line contains "Y" then that line and the original line (first line in this case) will need to be deleted. Lines 2 and 4 will remain because "Y" is not present. This information will then be put into a different file while preserving the original file. After the quotes are stripped the file will look as follows:
180223,1,7.3,1Z0E947E0357325461,6.53,UPAC,N 180225,1,7.3,1Z0E947E0355178080,9.49,UPAC,N 180223,1,7.3,1Z0E947E0357325461,6.53,UPAC,N
I know I am asking for quite a lot but any help would be greatly appreciated. Thank you.The problem is not too hard. But not so easy either. Batch files, by nature, do not readily handle Coma Seperated Values format, or CSV. That is more easily don in Excel or a similar spreadsheet program.
Do you have the KILLS to do this, at LEST in part, in some other program? Do you know VBA? Or anything like hat?
A piratical solution is to make a hybrid. Part in 'batch' and part in a SCRIPT you already know.
Of COURSE, if needed, it can all be done in Batch. It is not very elegant.
The FOR statement can read lines from a text file ans separate the items in local variables that are used inside a block of a FOR construct.
Sorry I can not able to write such code, but just wait a bit, somebody ELSE can help you. The only way I could do this is by breaking in up into modules and or do some of the script in a general purpose programming language. Thank you for responding Geek-9pm. Unfortunately, I do not have the skills for VBA and not sure how to automate this in Excel. I will look into it though. I do need to make a correction, however, to the expected output. Thanks again.
Corrected Output: Quote 180223,1,7.3,1Z0E947E0357325461,6.53,UPAC,N 180225,1,3.9,1Z0E947E0355178080,4.77,UPAC,N 180223,1,7.3,1Z0E947E0357325461,6.53,UPAC,N
|