search two files for specific words remove the line from one file
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The fgrep name is just a shortcut for grep -F which was shown above in post #2. But that is for fixed strings not patterns. Now that you want to anchor the string, you have to make a pattern.
My apologies. I honestly didnt know that fgrep was the same as grep -F. Im still new at all of this as I dont constantly work with it everyday.
I didnt quite understand this portion of it in Post#2 <(awk '$0=$2' file1) though.
Within file1 there is just one word per line. Im looking to have that word start the line within file2 and if it does, remove that line only.
I would have to say there are maybe 50 lines...
No worries. No matter which direction one chooses to look there are far more details than it is possible to absorb. You eventually learn to kind of swim in it and navigate between parts that have become familiar through use.
The <( ... ) annotation is a process substitiution where the output of the enclosed clause is treated as an input (or output) file itself. See also the Advancced Bash-scripting Guide's section on process substitution.
It is a mainly Bashism but also found in Zsh and maybe a few other advanced shells.
Try the example in #15 above. It turns each line of file1 into a pattern using process substitution.
No worries. No matter which direction one chooses to look there are far more details than it is possible to absorb. You eventually learn to kind of swim in it and navigate between parts that have become familiar through use.
The <( ... ) annotation is a process substitiution where the output of the enclosed clause is treated as an input (or output) file itself. See also the Advancced Bash-scripting Guide's section on process substitution.
It is a mainly Bashism but also found in Zsh and maybe a few other advanced shells.
Try the example in #15 above. It turns each line of file1 into a pattern using process substitution.
Quote:
Try the example in #15 above. It turns each line of file1 into a pattern using process substitution.
Seems to be working but not sure... it is taking an awful long time to complete.
In many cases it's sufficient to require boundaries at both ends.
grep has the -w option (word match)
Code:
grep -vwf file1 file2
Your examples differ a bit from your written requirements.?
A comment to
awk -F\.
I think it's the same as
awk -F.
-F sets FS (FieldSeparator). GNU awk treats a single character as a character set.
For clarity and portability, you can explicitly give the character set as
awk -F"[.]"
Last edited by MadeInGermany; 11-20-2021 at 08:49 AM.
In many cases it's sufficient to require boundaries at both ends.
grep has the -w option (word match)
Code:
grep -vwf file1 file2
word match would indicate it will look for the such words in any line and remove those lines, correct? Im looking for the such word at the beginning of the line and remove that line only. Thank you!
What is the difference between fgrep -vf file1 file2 and grep -vwf file1 file2
First line
real 0m0.306s
user 0m0.276s
sys 0m0.040s
Second line
real 0m1.111s
user 0m1.072s
sys 0m0.042s
However the output doesnt look proper with either of those ways as Im missing a lot of other lines within file2. The output looks proper doing it this way though and the time is in-between both of them but closer to the second one.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.