Problem using grep -f
Hi all,
I'm trying to manipulate a large text file full of records (metadata - one complete record per line). I need to delete every line on which certain words appear - there are five different words, all pretty simple all-caps strings with occasional whitespace (like ADVISORY and EDITOR'S NOTE) I tried using grep -v, which worked a treat, but only string-by-string. Ideally I'd like to run this as grep -v -f, where the file targeted by the -f contains the strings I need to match in order to delete the lines they're in. i.e grep -v -f filecontainingSTRINGS.txt targetfile.txt > outputfile.txt When I try this, however, I don't get any matches - or more specifically, no changes are made in the output file. It works fine if there's only one string in filecontainingSTRINGS, but it doesn't work if there's more than one (I'm using newline as the delimiter). (Also my machine doesn't recognise /usr/xpg4/bin/grep - no idea what that's all about!) Any ideas? All help much appreciated! |
Quote:
are you sure that every string is on its own line? Also, I see a windows logo on the left side. Are you trying to edit windows files in linux? If so, then try to convert the files you are using to unix format first: dos2unix file.txt |
Hi zoeplankton and welcome to LQ,
you may search for lines with Upercase letters: Code:
grep -e [A-Z] file Code:
grep -v -e [A-Z] file Code:
grep -v -e [A-Z] file > newfile Code:
man sed |
Quote:
The "problem" here is that you're saying to don't want to see any lines that have ALL words from your file in one line. If your solaris has has a decent egrep you could try Code:
egrep -v "$(sed 's/\n/|/g' filecontainingSTRINGS)" targetfile.txt > outputfile.txt Cheers, Tink |
Quote:
************************** Update - yup, that was the problem. Fixed now, thanks! |
Quote:
|
All times are GMT -5. The time now is 10:52 AM. |