I'm quite new at Awk. I have a folder with an awk script and a file named MODELE1. I am trying to run my script, more specifically the lines:
awk '($1 != "GRID") {print $0}' MODELE1 > MAIL_SANS_GRID
awk "($1 == "GRID") {print $0}" MODELE1 | sort -n -k 2,2 > GRID_REP_COQ
But I get the error
^ invalid char ''' in expression
For the '...'
I've tried to change it to ...
and " ..." . In the first case, I get the same error message and in the second, I have a syntax error for the "sort".
Does anyone know how to solve it?
Thanks in advance.
EDIT: for clarity, here is the whole script, called grid_sorting:
#!/bin/awk -f
# Model and GRID cards extraction
awk '($1 != "GRID") {print $0}' MODELE1 > MAIL_SANS_GRID
# GRID sorting
awk '($1 == "GRID") {print $0}' MODELE1 | sort -n -k 2,2 > GRID_REP_COQ
# Model and sorted GRID cards concatenation
cat MAIL_SANS_GRID GRID_REP_COQ > MODELE
I then run the script in a terminal using the command
./grid_sorting
I get the errors:
awk: ./grid_sorting:4: awk '($1 != "GRID") {print $0}' MODELE1 > MAIL_SANS_GRID
awk: ./grid_sorting:4: ^ invalid char ''' in expression
awk: ./grid_sorting:4: awk '($1 != "GRID") {print $0}' MODELE1 > MAIL_SANS_GRID
awk: ./grid_sorting:4: ^ syntax error
If I switch to double quotes :
#!/bin/awk -f
# Model and GRID cards extraction
awk "($1 != "GRID") {print $0}" MODELE1 > MAIL_SANS_GRID
# GRID sorting
awk "($1 == "GRID") {print $0}" MODELE1 | sort -n -k 2,2 > GRID_REP_COQ
# Model and sorted GRID cards concatenation
cat MAIL_SANS_GRID GRID_REP_COQ > MODELE
I get the error:
awk: ./grid_sorting:6: awk "($1 == "GRID") {print $0}" MODELE1 | sort -n -k 2,2 > GRID_REP_COQ
awk: ./grid_sorting:6: ^ syntax error
And the intermediate file MAIL_SANS_GRID is created but is empty.