Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
3 added 13 characters in body
source | link
awk -v OFS='\t' '$4 !~ /^[pm]iRNA/ { $4 = "rfam" } ; { $4 = $4 ; print }' file

This does exactly what you asked for - if field 4 doesn't match the regexp ^[pm]iRNA, set it to rfam. Then print the line whether it was changed or not.

Note: I've set the Output Field Separator (OFS) to a tab to ensure consistent output, and added $4 = $4 before the print statement (which has the side-effect of causing the field sepseparator in the output line to be changed to OFS) - otherwise lines that have been changed will have the OFS as the default (a single space) while unchanged lines will be unchanged from what they were in the original file, potentially causing the columns to not line up correctly when viewed with in a terminal with cat or whatever.

awk -v OFS='\t' '$4 !~ /^[pm]iRNA/ { $4 = "rfam" } ; { $4 = $4 ; print }' file

This does exactly what you asked for - if field 4 doesn't match the regexp ^[pm]iRNA, set it to rfam. Then print the line whether it was changed or not.

Note: I've set the Output Field Separator (OFS) to a tab to ensure consistent output, and added $4 = $4 before the print statement (which has the side-effect of causing the field sep in the output line to be changed) - otherwise lines that have been changed will have the OFS as the default (a single space) while unchanged lines will be unchanged from what they were in the original file, potentially causing the columns to not line up correctly when viewed with in a terminal with cat or whatever.

awk -v OFS='\t' '$4 !~ /^[pm]iRNA/ { $4 = "rfam" } ; { $4 = $4 ; print }' file

This does exactly what you asked for - if field 4 doesn't match the regexp ^[pm]iRNA, set it to rfam. Then print the line whether it was changed or not.

Note: I've set the Output Field Separator (OFS) to a tab to ensure consistent output, and added $4 = $4 before the print statement (which has the side-effect of causing the field separator in the output line to be changed to OFS) - otherwise lines that have been changed will have the OFS as the default (a single space) while unchanged lines will be unchanged from what they were in the original file, potentially causing the columns to not line up correctly when viewed with in a terminal with cat or whatever.

2 added `-v OFS='\t'` for tabbed output and explained why.
source | link
awk -v OFS='\t' '$4 !~ /^[pm]iRNA/ { $4 = "rfam" } ; { $4 = $4 ; print }' file

This does exactly what you asked for - if field 4 doesn't match the regexp ^[pm]iRNA, set it to rfam. Then print the line whether it was changed or not.

Note: I've set the Output Field Separator (OFS) to a tab to ensure consistent output, and added $4 = $4 before the print statement (which has the side-effect of causing the field sep in the output line to be changed) - otherwise lines that have been changed will have the OFS as the default (a single space) while unchanged lines will be unchanged from what they were in the original file, potentially causing the columns to not line up correctly when viewed with in a terminal with cat or whatever.

awk '$4 !~ /^[pm]iRNA/ { $4 = "rfam" } ; { print }' file

This does exactly what you asked for - if field 4 doesn't match the regexp ^[pm]iRNA, set it to rfam. Then print the line whether it was changed or not.

awk -v OFS='\t' '$4 !~ /^[pm]iRNA/ { $4 = "rfam" } ; { $4 = $4 ; print }' file

This does exactly what you asked for - if field 4 doesn't match the regexp ^[pm]iRNA, set it to rfam. Then print the line whether it was changed or not.

Note: I've set the Output Field Separator (OFS) to a tab to ensure consistent output, and added $4 = $4 before the print statement (which has the side-effect of causing the field sep in the output line to be changed) - otherwise lines that have been changed will have the OFS as the default (a single space) while unchanged lines will be unchanged from what they were in the original file, potentially causing the columns to not line up correctly when viewed with in a terminal with cat or whatever.

1
source | link

awk '$4 !~ /^[pm]iRNA/ { $4 = "rfam" } ; { print }' file

This does exactly what you asked for - if field 4 doesn't match the regexp ^[pm]iRNA, set it to rfam. Then print the line whether it was changed or not.