I have to implement in an awk script (in a file containing the shebang #!/usr/bin/awk -f
, not using a command line) the following: first of all, we have to ask the user to enter the value of a college type, which can be AFA, CEE, CFA and EASD. The value you enter should be stored in the variable center . From this value it is necessary to extract the rows of a file file1 whose column 2 contains the value of this variable, and save all these rows in the file file2. For example:
awk '/SCHOOL/ { print }' file1
The file file1 contains the following information:
Center_code Name City_code
800 SCHOOL NUMBER ONE 8000
801 SCHOOL NUMBER TWO 8010
802 INSTITUTE GALCERAN PINE 8020
803 EASD PINE 8030
804 SCHOOL NUMBER THREE 8040
805 INSTITUTE CAN CLOS 8050
806 ESCRBC CAT 8060
807 SCHOOL NUMBER FOUR 8070
If the user enters the value SCHOOL , the rows that contain the value SCHOOL in the Name column must be taken , and all these rows must be saved in a different file.
How can I do it? Thanks in advance.
Create a given script and call it with:
Inside you
archivo.awk
reference the variablecenter
and do something like:O well
If it's a script:
Let's see a complete example:
The script:
We execute:
To save to another file, we redirect with
comando > fichero_destino
: