Hi,
I'm trying to edit every line in a file with awk. I'm matching a pattern, and then splitting and removing the section of the line after and including the match.
This is the line that i am using:
awk -F '_contigs' '{print $1}' before.txt > after.txt
My problem is that each line in the file that doesnt contain any string matching the given pattern gets passed as an empty line, losing the values in all of these rows in the final output.
Is there something i can pass to awk to tell it to ignore these lines and pass them unedited? Or is there a way to nest the awk in a loop and only process lines matching the pattern?
For example, i have the following list:
1_unscaffolded
2_unscaffolded
3_unscaffolded
scaffold1_contigs_1234
scaffold2_contigs_5678
scaffold3_contigs_9101112
I want the end result to be:
1_unscaffolded
2_unscaffolded
3_unscaffolded
scaffold1
scaffold2
scaffold3
But what i get with the above code is:
scaffold1
scaffold2
scaffold3
Thanks
*Edited to add example
without example data, it is difficult to understand your query. Post some example data and expected outcome. Since this is not a relevant biology problem, this post may be marked non-relevant to the forum if you do not provide the context of the query and example data.
My bad. Have edited with an example