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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
06-28-2012, 09:13 AM
|
#1
|
LQ Newbie
Registered: Jun 2012
Posts: 6
Rep: 
|
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 09:14 AM.
|
|
|
06-28-2012, 09:50 AM
|
#2
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,336
|
You need to use word boundaries to ensure you get the construct you want.
You might find grep easier for that.
|
|
|
06-28-2012, 10:01 AM
|
#3
|
LQ Newbie
Registered: Jun 2012
Posts: 6
Original Poster
Rep: 
|
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.
|
|
|
06-28-2012, 10:20 AM
|
#4
|
Member
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45
Rep:
|
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 lin e without that l ett er as a standalon e word
This is a e lin e for t esting
This command will only return the second line:
Code:
cat test.txt | grep -w "e"
Last edited by montel; 06-28-2012 at 10:28 AM.
Reason: missed an "e" :P
|
|
|
06-28-2012, 10:33 AM
|
#5
|
LQ Newbie
Registered: Jun 2012
Posts: 6
Original Poster
Rep: 
|
Quote:
Originally Posted by montel
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 lin e without that l ett er as a standalon e word
This is a e lin e for t esting
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 :-)
|
|
|
06-28-2012, 10:40 AM
|
#6
|
Member
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45
Rep:
|
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
|
|
|
06-28-2012, 10:50 AM
|
#7
|
LQ Newbie
Registered: Jun 2012
Posts: 6
Original Poster
Rep: 
|
Quote:
Originally Posted by montel
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]
|
|
|
06-28-2012, 10:52 AM
|
#8
|
Member
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45
Rep:
|
No problem, glad you figured it out 
|
|
|
All times are GMT -5. The time now is 10:57 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|