I have an excel file that have a random count of columns/fields and what im trying to do is to only retrieve all the rows under 2 specific field headers.
I can use the usually command for awk which is awk 'print{ $1 $2}' > output.txt, but the location of the 2 specific field headers is not constant so it will not be useful to use the command.
example:(headers needed are name & age)
for today the generated column count and location of needed headers are:
name age sex location company
the next day the column count and location of the needed headers might be
company age location id name address
Is there a command that can be used just to read the headers that i just need and then once the headers are found retrieve all the rows under the header and place them to output.txt?
i tried to copy paste the exact code to mdat.sh and also the input file to mdat.txt and when i executed mdat.sh it only showed blank rows and no data in it...
NR==1 { # Select first line = header
for (i=1; i<=NF; i++) # For every field i (NF is last field# )
col_fields[$i] = i; # Memorize field# for column name ($i)
}
{ # Select every line
out = ""; # Initialize out valriable (used for line diplay)
for (i=1; i<=cols_count; i++) { # For every selected columns
col_hdr = cols; # get column name
out = (i>1 ? out OFS : "") (col_fields[col_hdr] ? $(col_fields[col_hdr]) : "?" );
# Concatenate column value $(col_fields[col_hdr]
# to out variable with Output Field Separator
} #
print out; # Print columns
}