LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how can delete certain word from file (https://www.linuxquestions.org/questions/linux-general-1/how-can-delete-certain-word-from-file-610398/)

Barq 01-01-2008 02:02 PM

how can delete certain word from file
 
I have text file which has 1 word per line , but there are lines which has word from 1 or 2 character like as in on ,etc. I want to delete this word from my file, how can i do that.

Uncle_Theodore 01-01-2008 02:11 PM

sed '/<word_to_delete>/d' -i <filename>

Barq 01-01-2008 02:16 PM

thank you, but i want to delete every word contain just 1 or 2 character , there are many word , how can do that?

Uncle_Theodore 01-01-2008 02:33 PM

Oh, sorry, didn't get your question at first.. This
sed '/^..$/d' -i <filename>
should remove all lines that comtain only two characters. Similarly for 1-character lines
sed '/^.$/d' -i <filename>

Barq 01-01-2008 02:48 PM

thank you,

now,

i have 2 file , i want to know which word that locate in two file?

Uncle_Theodore 01-01-2008 02:59 PM

Do you want to know which file contains a specific word? Then you need the grep command.
Or, are you asking which words will the abovementioned commands delete?
I didn't quite get your question, sorry.

Barq 01-01-2008 03:04 PM

look

first file 1.txt has some words , 2nd file 2.txt has some words , both file has some same words , i want to know this words.

thank very much

Uncle_Theodore 01-01-2008 07:25 PM

Well, the only thing I can come up with is something like this

sort textfile.txt > tempfile1 && sort textfile1.txt > tempfile2 && comm tempfile1 tempfile2 && rm tempfile1 tempfile2

Also, you might wanna look at man comm

trickykid 01-01-2008 07:40 PM

Is this homework? Sure sounds like homework the way your asking your questions and not being very clear on your questions, then coming up with more questions?

Barq 01-01-2008 10:29 PM

thank you Uncle_Theodore



Mr trickykid,

this is not home work , i am already graduating from univ. And it is not my habit to ask many, but my knowledge about text processing is not good, that set.

Mr trickykid, do't accuse from your imagination without ask me first , because life is not standard case.

trickykid 01-02-2008 09:15 AM

Quote:

Originally Posted by Barq (Post 3008140)
thank you Uncle_Theodore



Mr trickykid,

this is not home work , i am already graduating from univ. And it is not my habit to ask many, but my knowledge about text processing is not good, that set.

Mr trickykid, do't accuse from your imagination without ask me first , because life is not standard case.

I thought I did ask. That's why I have ? at the end of each sentence. So before you start accusing me of anything, better look twice that I have moderator under my name and I'm doing my job for the integrity of this site by probing suspicious threads/questions, etc. You're posts seem fishy, you worded your questions as if they were homework, don't do that if you don't want to be accused. Now, go read up on sed, awk and grep.

xptools 01-06-2008 07:06 PM

I 2nd to trickykid's suspicious.

Quote:

Now, go read up on sed, awk and grep.
If you have no clue where to start, start here: sed/awk/sh/csh tutorials

And you can go further on other File/Text Processing Tools as well.


All times are GMT -5. The time now is 10:59 PM.