LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 02-16-2009, 03:23 PM   #1
rtrahan
Member
 
Registered: Jan 2009
Location: Georgia
Distribution: OpenSuse Fedora
Posts: 64

Rep: Reputation: 17
Commands and Common Expressions-ls/grep


I didn't know exactly where to post this but since I am a newbie studying for the Linux+ figured here was best choice...

Scenario:
I have a file named novowel, with the following words; efgh ijkl abcd

I won't to run the expression [^abcd] which should bring all the words that don't include abcd. I tried ls [^abcd] novowel: but got ls: cannot access [^abcd]: No such file or directory novowel and I tried ls novowel [^abcd]
but got same error.

I tried grep [^abcd] novowel
and got - efgh ijkl abcd
so it brought back all the words.

Just trying to find command that works with the [^...] expression.

Thanks in advance
 
Old 02-16-2009, 03:40 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
sed 's/ /\n/g' testfile | grep [^abcd]
The sed command put words on different lines, so you can use grep this way.
 
Old 02-17-2009, 04:26 AM   #3
rtrahan
Member
 
Registered: Jan 2009
Location: Georgia
Distribution: OpenSuse Fedora
Posts: 64

Original Poster
Rep: Reputation: 17
Yes, but what if I wanted to use the command to search a document. I would not have the flexibility to move anything around? I'll keep looking for a command that works with
[^abcd]. If you or anyone have a different input I would appeciate it.
 
Old 02-17-2009, 04:47 AM   #4
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Rep: Reputation: 30
rtrahan,

Can you explain your need on a more elaborate way?

Code:
just trying to find command that works with the [^...] expression.
All BRE's , ERE's can do that.
 
Old 02-17-2009, 07:48 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Using awk you can split each line of a file into words and each word into single characters. If and only if a character in a word does not match the complement of abcd, the word is deleted:
Code:
awk '{
  for ( i = 1; i <= NF; i++ )
    for ( j = 1; j <= length($i); j++ )
      if ( substr($i,j,1) !~ /[^abcd]/ )
        gsub($i,"",$i)
  print
}' novowel
I'm not really sure this is what you're looking for, anyway!
 
  


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
using grep with expressions ANDed logicalfuzz Linux - Newbie 20 11-16-2010 12:17 AM
Trying to look at sources for common unix/linux commands IanGlenn Linux - General 2 05-02-2008 04:56 AM
Regular expressions using grep linuxmandrake Programming 3 11-16-2005 04:29 PM
Commands in Gnome (and common X programs) detly Linux - Software 3 11-16-2005 01:54 AM
Why aren't common commands working? NewTuxGirl Linux - Newbie 8 06-07-2004 10:42 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration