I have a file that I am attempting to strip customer names from using AWK. The file is a fixed width file, and every column has meaning.
The file consists of many lines, all the same format, very similar to the below:
1234-123 123456 12345678901234CUSTOMER NAME TO REMOVE12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
1234-123 123456 12345678901234CUSTOMER NAME TO REMOVE12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
1234-123 123456 12345678901234CUSTOMER NAME TO REMOVE12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
1234-123 123456 12345678901234CUSTOMER NAME TO REMOVE12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
It is the customer name that I need to swap with an imaginary name so that the desired output is:
1234-123 123456 12345678901234SENTINAL PRIME 12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
1234-123 123456 12345678901234OPTIMUS PRIME 12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
1234-123 123456 12345678901234BUMBLE BEE 12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
1234-123 123456 12345678901234IRON HIDE 12345-1234 TRN 123-123 12345678901-1234 TRN 12345678
I have a list of transformer names that I would like to use for this, stored in a file called transformer.names
.
SENTINEL PRIME
OPTIMUS PRIME
BUMBLEBEE
IRONHIDE
However, to keep each line of the original file the same width, I need to right pad the transformer names with spaces as the transformer names I have are all different lengths.
It seems to be possible to right pad these names to a certain length using AWK but I have not managed to figure it out (or find a clear enough answer) for me to understand yet.
Below is my current AWK script.
#!/usr/bin/awk -f
BEGIN {
}
{
getline line < "transformer.names"
print substr($0, 0, 30) line substr($0, 62, 120)
}
I run it with this command:
my_program.awk my-file.txt
I think I can include a line something like this in place of the print line above, however I have not managed to get it working yet.
printf "-%32s|", substr($0, 0, 30) line substr($0, 62, 120)
Any tips would be fantastic!