1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

xargs and grep

Discussion in 'Linux & Open Source' started by Nefarious, Dec 20, 2019.

  1. Nefarious

    Wise Guy

    Joined: Aug 1, 2003

    Posts: 1,049

    I wanted to grep -v a text file, but the file was too long, so I did the standard thing of piping to xargs grep, but the text file contains a list of file names and when piped to xargs, it tries to read the files rather than treating the output as text and running grep on the text - any suggestions?

    My first thought was to use sed to insert something at the beginning of each line but was wondering if there was a simpler method.
     
  2. AmateurExpert

    Gangster

    Joined: Aug 7, 2017

    Posts: 410

    Location: location location

    If you are trying to grep -v a large file that's >2.4G, why not split that file manually into smaller chunks and just grep -v those?

    If you just xargs grep the list of filenames without giving grep a FILE of "-", I suspect grep will look for matches (or the inverse in this case) within each file rather than the std input text itself.
     
  3. Nefarious

    Wise Guy

    Joined: Aug 1, 2003

    Posts: 1,049

    Turns out, there was no problem with running grep just from bash - the only thing in the text file that didn't match the string was the line 'too many arguments'..... it took me hours to figure that out, felt like such an idiot
     
  4. AmateurExpert

    Gangster

    Joined: Aug 7, 2017

    Posts: 410

    Location: location location

    Haha! Love that one, good story to tell the grandkids maybe :)