While it is true that there are 18 fields in the heading line in file1, there are a lot more fields on subsequent lines in that file. The
cut command you suggested would copy the input file to its output and add 16 trailing <tab> characters to each input line. Using
awk to delete field
$18 (assuming we set the
awk field delimiter to four <space> characters would seem to be a request to delete the header line completely (
$otherinfo expanding to
$0 unless
otherinfo is defined to be some numeric value) and to remove the first field on your other sample lines (since field 18 on the other lines is in
file1 is
1).
And you haven't said how you "
match" 17 fields from
file1 (after removing the last 13 fields) with lines from
file2 containing 10 fields. Do you match lines from
file1 (after skipping line1) with lines from
file2 (after skipping lines that start with a "#") sequentially? Do you match lines with identical field 2 values in both files? Or, is there some other criteria used to determine a match?
From the sample input and output you provided, I would guess that you are trying to:
- Keep the header from file1 unchanged.
- Keep the 1st 17 fields from other lines in file1 unchanged; delete all other fields at the end of those lines; and if and only if there is a line in file2 with a field 2 that matches field 2 in this line, add the last four single <space> separated fields from the matched line in file2.
Is that an accurate statement of your requirements?