Skip to main content
9 events
when toggle format what by license comment
Apr 18, 2021 at 16:11 comment added ilkkachu @Esteban, then you're doing something other than just removing the empty line. Also, note that text files are supposed to end with a newline character, but some editors allow moving the cursor "below" the last line (that makes it easier to add a new line by just going there and typing, instead of having to go to the end of previously-last line just to hit enter, needing a separate command for adding the new line). Since you mention Windows, you might want to check that you're not trying to have grep read patterns off a file with Windows line endings, i.e. with the extra carriage returns.
Apr 17, 2021 at 21:06 comment added Esteban So I think the problem is that I generated file1 (the list of terms to grep) using write.table function in R, and this adds the empty line at the end of the file. But in fact, I can only see this empty line when I open file1 with a Windows text editor like Notepad++. If I open file1 using Vi in Bash, or look at it using tail file1, no empty line is apparent. So I guess R has put something at the end of the file which messes things up...?
Apr 17, 2021 at 21:05 comment added Esteban Thank you both for your help. I messed up by failing to say the problem is that the grep returns no results (not all results, as you both assumed). I played around a bit more trying to generate a reproducible example, and I can see that my commands and the ones you suggested work fine on simplified data.
Apr 17, 2021 at 19:50 answer added ilkkachu timeline score: 2
Apr 17, 2021 at 18:47 review First posts
Apr 20, 2021 at 7:46
Apr 17, 2021 at 18:44 comment added Uprooted In second command you forgot -f, should work like this: grep . file1 | grep -wF -f - file2 > file3
Apr 17, 2021 at 18:33 history edited berndbausch CC BY-SA 4.0
format
Apr 17, 2021 at 18:28 comment added Uprooted Empty line is a zero-length pattern, so it matches every line I guess.
Apr 17, 2021 at 18:22 history asked Esteban CC BY-SA 4.0