LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-28-2012, 08:13 AM   #1
DarkLight90
LQ Newbie
 
Registered: Jun 2012
Posts: 6

Rep: Reputation: Disabled
delete lines that contain an EXACT word


Hi all,
this is my first post, please be patient :-)

this is my text file:

5326
71 e
68 di
39 €
26 del
25 per
25 in
22 il
22 ebay
20 eur
19 la
19 iphone
16
15 nero
15 a
and so on...........

it contains the occurences of words in a text file but i need to delete lines containing italians adverbs or conjunctions (like "per", "di" or "e"); i tried like this:

Code:
sed -e 's/e//g' output.txt > output2.txt
but this instruction delete ALL LINES CONTAINING CHAR "e"...

i tried also this:

Code:
sed -e 's/ e/n//g' output.txt > output2.txt
but nothing...

Any suggestion? Thanks

Last edited by DarkLight90; 06-28-2012 at 08:14 AM.
 
Old 06-28-2012, 08:50 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,177

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
You need to use word boundaries to ensure you get the construct you want.

You might find grep easier for that.
 
Old 06-28-2012, 09:01 AM   #3
DarkLight90
LQ Newbie
 
Registered: Jun 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
You need to use word boundaries to ensure you get the construct you want.

You might find grep easier for that.
Thanks syg00, but i really don't know how to modify this instruction that build this list i wrote before:

Code:
cat webpage.txt | tr -d '[:punct:]' | tr ' ' '\n' | tr 'A-Z' 'a-z' | sort | uniq -c | sort -rn > output.txt
webpage.txt is the page from where i need the words count... What can i do for simplify my problem?

In meanwhile i try to find a solution with egrep.

Thanks again.
 
Old 06-28-2012, 09:20 AM   #4
montel
Member
 
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45

Rep: Reputation: 18
Not sure if you have already looked at this, since the last comment was to use grep, but i'll give some input.

The -w flag for grep will match standalone words, so if you have a line like this: (test.txt)

This is a line without that letter as a standalone word
This is a e line for testing

This command will only return the second line:

Code:
cat test.txt | grep -w "e"

Last edited by montel; 06-28-2012 at 09:28 AM. Reason: missed an "e" :P
 
Old 06-28-2012, 09:33 AM   #5
DarkLight90
LQ Newbie
 
Registered: Jun 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by montel View Post
Not sure if you have already looked at this, since the last comment was to use grep, but i'll give some input.

The -w flag for grep will match standalone words, so if you have a line like this: (test.txt)

This is a line without that letter as a standalone word
This is a e line for testing

This command will only return the second line:

Code:
cat test.txt | grep -w "e"
Yeah u are right motel, i was thinking right now at this but there is no "-exec" for "sed" command, so i don't know how to do a pipe of instructions for deleting what i don't need (selecting whit grep)... also "tr" don't implement this function...

Thanks anyway :-)
 
Old 06-28-2012, 09:40 AM   #6
montel
Member
 
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45

Rep: Reputation: 18
I am not sure how to "delete" the line using grep, but this will output only the lines that do not contain that letter as its own word:

Code:
grep -vw "e" example.txt >> newExample.txt
I am not well versed in what you are using in your command, but could you do something like this?

Code:
cat webpage.txt | grep -vw "e" | tr -d '[:punct:]' | tr ' ' '\n' | tr 'A-Z' 'a-z' | sort | uniq -c | sort -rn > output.txt
 
Old 06-28-2012, 09:50 AM   #7
DarkLight90
LQ Newbie
 
Registered: Jun 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by montel View Post
I am not sure how to "delete" the line using grep, but this will output only the lines that do not contain that letter as its own word:

Code:
grep -vw "e" example.txt >> newExample.txt
I am not well versed in what you are using in your command, but could you do something like this?

Code:
cat webpage.txt | grep -vw "e" | tr -d '[:punct:]' | tr ' ' '\n' | tr 'A-Z' 'a-z' | sort | uniq -c | sort -rn > output.txt
So great, man! :-D "-vm" that was what i really need of grep!
Thanks a lot!

[SOLVED]
 
Old 06-28-2012, 09:52 AM   #8
montel
Member
 
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45

Rep: Reputation: 18
No problem, glad you figured it out
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
delete top lines of a text file until a word is met njfhdsiue Linux - Software 3 07-07-2011 03:48 AM
Search word and delete only the word and the line using Sed command kbmukesh Linux - Newbie 4 06-28-2011 06:35 AM
[SOLVED] Delete range word to word with sed when all you have is one line subby80 Linux - Enterprise 16 09-02-2010 05:04 AM
print second word in 1st line along with 5th word in all the lines after the first bangaram Programming 5 08-31-2009 03:42 AM
command for grep the exact word nagendrar Linux - Newbie 7 04-29-2009 02:33 PM


All times are GMT -5. The time now is 04:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration