find one field into another
Hi guys !
Using awk, I try to read a column and see if a string from a field in this column is present into a longer string from another field in the same column. If it is the case, returns the sub-string length (RLENGTH) in a new field. input: Code:
111|abcd1234efgh|zzzzz Code:
awk 'BEGIN{FS=OFS="|"} {match(a[$2],$2); print $4 = RLENGTH}1' input Code:
111|abcd1234efgh|zzzzz|8 But I don't manage to write a for loop to scan the entire column by taking every field one by one as a reference for match function. It returns $4 = "-1" for every record. |
I reckon you can extend this one liner to match first, then sort by length http://unstableme.blogspot.com.au/20...g-awk-and.html & only print last record
|
Hi Chrism01, thanks for your help !
The problem is that it doesn't tell me if it found the shorter string within another field ($4 = -1 for all records). |
edited first post
|
not sure what you are trying to do (shouldnt your 3rd row = 6 ?).
anyways, this is my stab at it: Code:
[schneidz@hyper ~]$ cat lcvs.txt |
All times are GMT -5. The time now is 03:57 AM. |