LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-01-2008, 02:02 PM   #1
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Rep: Reputation: 15
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.
 
Old 01-01-2008, 02:11 PM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
sed '/<word_to_delete>/d' -i <filename>
 
Old 01-01-2008, 02:16 PM   #3
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Original Poster
Rep: Reputation: 15
thank you, but i want to delete every word contain just 1 or 2 character , there are many word , how can do that?
 
Old 01-01-2008, 02:33 PM   #4
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
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>
 
Old 01-01-2008, 02:48 PM   #5
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Original Poster
Rep: Reputation: 15
thank you,

now,

i have 2 file , i want to know which word that locate in two file?
 
Old 01-01-2008, 02:59 PM   #6
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
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.
 
Old 01-01-2008, 03:04 PM   #7
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Original Poster
Rep: Reputation: 15
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
 
Old 01-01-2008, 07:25 PM   #8
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
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
 
Old 01-01-2008, 07:40 PM   #9
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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?
 
Old 01-01-2008, 10:29 PM   #10
Barq
Member
 
Registered: Aug 2004
Location: EGYPT
Distribution: FEDORA 10
Posts: 114

Original Poster
Rep: Reputation: 15
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.
 
Old 01-02-2008, 09:15 AM   #11
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by Barq View Post
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.
 
Old 01-06-2008, 07:06 PM   #12
xptools
Member
 
Registered: Sep 2005
Location: Canada
Distribution: Debian Testing
Posts: 40

Rep: Reputation: 15
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.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to make a link from word in one file to a different file using Ubuntu linux gilbert.baumslag Linux - Newbie 3 01-11-2008 01:32 PM
help... get single word from file night-blade1 Programming 3 10-12-2004 08:58 AM
file+word problems warney_out Programming 3 09-02-2004 05:32 AM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 02:46 AM
MS Word file converter? pepelaz Linux - Software 4 12-12-2003 03:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:48 AM.

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
Open Source Consulting | Domain Registration