I made a rash statement yesterday that I could do this easier in Linux than on Windows with VBS but looking at it I'm a bit stuck.
I have a large fixed-width data file auto-generated by a database for printing delivery labels that's full of tags and flags for the printers. I need to compare the account numbers within the file to a list in a second file and add +14D to one of the fields for those accounts found in the list. So a line beginning %2403 needs a flag inserting at position 26(REPLACING 3 spaces to keep the field lengths correct) ONLY where the account number is in the list.
I'm a bit stumped by this one as to the most efficient way to read and compare the 2 files as speed is of the essence here. I'll probably use sed to do the substitutions.
I think what I'm going to look at is since the customer code is the first part of the file name, I'll have a lookup file (a bit like an ini file) with the customer code as the section heading and account codes below it - so for example:
[HLCCK]
123456
654321
789456
987654
[ABCDE]
or
[BBCMY]
3336662,567483,123456
[ZXCVB]
etc
Then all I need do is extract the cust. code from the file name then only look at those few account numbers, but still not sure how to do it. It's been a long time since I've had to do anything like this.
If you send samples, we can do this easily in a short Python or Perl script.
Basically:
Read check file into an array.
Look through big file, grabbing account # and checking if it's in the array with a hasIndex() function or similar. If found, do a simple replace function or regex.
If you want help with this, send sample files for both and I'll whip something up.
The lines with %2403+12 need to end up looking like:
%2403+1235932 +1300050+14D !
I almost get it, but please send two examples of the exact same lines "before and after." Also, in the check file a single line of comma-separated values?
Okay, but that still doesn't give me any before-and-after lines. In any case, I should be making you write the code yourself so I don't do your work for you.
Here's a functional but incomplete program that will do something a lot like what you want. Making all the changes are up to you.
This script opens a file and reads the first line, which contains comma-separated values for account numbers. It then loops through the second file and, when it finds one of those account numbers in a set position, it adds "ZZ" after it.
It doesn't preserve fixed-widths for different account number lengths, because I was lazy. But there should be plenty here to get you started.
Changes such as handling header records or having multiple lines with account files to check for I leave up to you. I hope this helps.
Hi Friends,
I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving...
File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Hi All,
Please help i have written an ksh script, where i am actually take count of lines in one file and want to update this count to 2nd field of a new file and apend the this into an existing file.
Note the below script is in for loop
-------- I am apending few records in a file... (7 Replies)
Hi all,
I have 2 files. One contains only 1 column and other one contains 2 columns, let say 1_col.txt and 2_col.txt respectively. Here, I will try to explain with an example.
Input files :
1_col.txt 2_col.txt
a a b
x a c
p ... (5 Replies)
Hi Gurus,
I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
how to list all files in current directory whose second character is a digit.
i guess i hav to use grep command + ls for this. but dont know how to use? (6 Replies)
Hi Experts.
I need to list the file and the filename comes from the file ListOfFile.txt.
Basicly I have a filename "ListOfFile.txt" and it contain
Example of ListOfFile.txt
/home/Dave/Program/Tran1.P
/home/Dave/Program/Tran2.P
/home/Dave/Program/Tran3.P
/home/Dave/Program/Tran4.P... (7 Replies)
I am trying to compare two file and make changes where ever its different.
for example:
Contents of file1
IP=192.165.89.11
NM=255.255.0.0
GW=192.165.89.1
Contents of file2
IP=192.165.89.11
NM=255.255.255.255
GW=192.165.89.1
NOTE HERE THAT NM IS DIFFERENT
So i want the changes... (6 Replies)
Hi all,
I am a newbie in unix shell script world. Say, I have a list of devices in file01 and then also have file02 with the list of the location. I need to telnet to each devices in file01 and set the location according to file02. Example:
#cat file01
ttnpx01
ttnpx02
nncrd01
nncrd02... (5 Replies)
In File A I have 1st col as numbers. Using these numbers, I need to find out
the rows at this numbered index in other file.
I know loose commands.
To get the 1st col from file A :
awk '{print $1}' fileA
To get the row at the index, say 100 - from file B :
sed '100p' fileB
After... (7 Replies)