I have 1344 ascii files with 3 columns and 68 rows of numerical values (no text/strings). They do not have any header, and the columns are space delimited.
I want to extract the value at 2nd column and 7th row from each one of those files, to create one file with one column and 1344 rows.
Example file 1:
0.11 3.1450 0.03
0.12 3.1210 0.04
0.13 3.1500 0.02
0.14 3.1530 0.03
0.15 3.1720 0.02
0.16 3.1170 0.04
0.17 3.1220 0.02
...
Example file 2:
0.11 3.1150 0.03
0.12 3.1410 0.04
0.13 3.2300 0.02
0.14 3.1230 0.03
0.15 3.3720 0.02
0.16 3.1370 0.02
0.17 3.2510 0.04
...
Output file:
3.1220
3.2510
...
I tried the following code:
awk '{for (i=7) {getline}; print NR,$2}' *
It gives me an error that the term is not recognised.
2
Answers
I just found another solution in matlab and posting the script here, in case anyone else needs it in future:
Using a small set of data for demonstration purposes:
One
awk
idea to extract the 2nd column from the 2nd row in each file:Where:
FNR==2
– if this is the 2nd record of a fileprint $2
– print 2nd columnnextfile
– cease processing current file and begin processing next fileFor OP’s requirement we replace
2
with7
: