awk abordagem:
awk '{print $0; if((getline nl) > 0){ print ($0!="not a color" && $0 == nl)?
nl=$0" is a color" : nl }}' file
A saída:
pink
pink is a color
not a color
not a color
violet
violet is a color
not a color
not a color
orange
orange is a color
not a color
You can use ‘getline var’ to read the next record from awk’s input into the variable var.
The getline command returns 1 if it finds a record and 0 if it encounters the end of the file.
$0!="not a color" && $0 == nl
- se o registro atual não for not a color
string AND 2 linhas conseqüentes forem iguais (dupicates)
Uma abordagem adicional usando substr()
function (para inserir " is a color "
string após os primeiros 2 caracteres da "cor" duplicada crucial):
awk '{print $0; if((getline nl) > 0){ print ($0!="not a color" && $0 == nl)?
nl=substr($0,1,2)" is a color "substr($0,3) : nl }}' file
A saída seria:
pink
pi is a color nk
not a color
not a color
violet
vi is a color olet
not a color
not a color
orange
or is a color ange
not a color