pmcmicha
Technical User
- May 25, 2000
- 353
I have a text file delimited by pipes from a database. I need to make certain modifications to these files.
FILE:
Field 1:Field 2:Field 3:Field 4:Field 5
xxxxxxx|xxxxxxx|/x/x/xx|xxxxxxx|xxxxxxx|
I need to remove the scatter path in Field 3 so that only the last entry in "/x/x/xx" exists in the new file.
FILE2:
xxxxxxx|xxxxxxx|xx|xxxxxxx|xxxxxxx|
I thought that I might be able to run with substr, but I have been unsuccessful so far. I am looking for a command that can be called with a ksh script.
This is what I have tried so far:
awk '{ $2 = substr($0, ("/"+1, $2)); print $0 }' ${FILE} > ${FILE2} # Doesn't error, but doesn't work either.
This one should work according to someone else I have been working with regarding this awk statement, but I think that you have to define the function "lastindexof"?
awk '{ $2 = substr(lastindexof("/"+1, $2)); print $0 }' ${FILE} > ${FILE2} # Always errors out.
Could someone please point in the right direction on this? Thanks in advance.
FILE:
Field 1:Field 2:Field 3:Field 4:Field 5
xxxxxxx|xxxxxxx|/x/x/xx|xxxxxxx|xxxxxxx|
I need to remove the scatter path in Field 3 so that only the last entry in "/x/x/xx" exists in the new file.
FILE2:
xxxxxxx|xxxxxxx|xx|xxxxxxx|xxxxxxx|
I thought that I might be able to run with substr, but I have been unsuccessful so far. I am looking for a command that can be called with a ksh script.
This is what I have tried so far:
awk '{ $2 = substr($0, ("/"+1, $2)); print $0 }' ${FILE} > ${FILE2} # Doesn't error, but doesn't work either.
This one should work according to someone else I have been working with regarding this awk statement, but I think that you have to define the function "lastindexof"?
awk '{ $2 = substr(lastindexof("/"+1, $2)); print $0 }' ${FILE} > ${FILE2} # Always errors out.
Could someone please point in the right direction on this? Thanks in advance.