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
222|1234|yyyyyyyyyy
333|ij1234k|xxx
444|ui987654g|ww
I tried using match function:
Code:
awk 'BEGIN{FS=OFS="|"} {match(a[$2],$2); print $4 = RLENGTH}1' input
to obtain:
Code:
111|abcd1234efgh|zzzzz|8
222|1234|yyyyyyyyyy|4
333|ij1234k|xxx|5
444|ui987654g|ww|-1
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.