I would like to be able to remove the first word written in capital after the period. The goal is to remove the first word written in capital letters even if the sentences on the same line are two. In fact, as I will show in the example, the first word of the line has been omitted, but the first word of the second sentence appears.
For the first sentence of the first line I solved the problem by starting the if from 2 instead of 1:
here's the code
BEGIN { FS="[^[:alpha:]']+"; OFS=" "}
{
parola=" "
max_nr=0
prec=""
for (i=2; i<=NF; i++) {
if ($i ~ /[[:punct:][:digit:]]+[:space:]*[A-Z][']{0,1}[A-Z]{0,1}[a-z]+/){
continue
}
else{
if ($i ~ /[A-Z][']{0,1}[A-Z]{0,1}[a-z]+/){
if(!(prec=="")){
prec=prec" "$i
}
else{
prec=$i
}
}
else {
if(!(prec=="")){
words[prec]
prec=""
}
}
if (i==NF) {
max_nr=max_nr+1
for (word1 in words) {
for (word2 in words) {
if (word1 != word2) {
print parola"" word1","word2
}
}
delete words[word1]
}
}
}
}
}
END{
print FILENAME" "FNR
print i
print max_nr
}
This is the content of test.txt:
Today Jonathan played soccer with Martin. After the game, Martin and Jonathan were thirsty and then drank a fresh Lemon Soda.
Paolo went to Lisbon with an Easyjet plane. During the trip he met two of his dear friends, Peter and John.
This is the result of the command:
awk -f script.awk test.txt > output.csv
Lisbon,During
Lisbon,John
Lisbon,Peter
Lisbon,Easyjet
During,John
During,Peter
During,Easyjet
John,Peter
John,Easyjet
Peter,Easyjet
Jonathan,Martin After
Jonathan,Lemon Soda
Jonathan,Martin
Martin After,Lemon Soda
Martin After,Martin
Lemon Soda,Martin
The expected output should be:
Lisbon,John
Lisbon,Peter
Lisbon,Easyjet
John,Peter
John,Easyjet
Peter,Easyjet
Jonathan,Martin
Martin,Lemon Soda
Jonathan,Lemon Soda
Any suggestions?