LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - News > Syndicated Linux News
User Name
Password
Syndicated Linux News This forum is for the discussion of Syndicated Linux News stories.

Notices


Reply
  Search this Thread
Old 06-20-2014, 08:41 AM   #1
LXer
LXer NewsBot
 
Registered: Dec 2005
Posts: 99,836

Rep: Reputation: 102Reputation: 102
LXer: Scripting a 4-Color Multiple Grepper


Published at LXer:

I wrote the shell script described here ('grep4') to find up to four items at the same time in my data tables, which are big text files with one record per line. The script gives each searched-for item its own color on the terminal screen. It lets me know in advance how many 'hits' there are, so that if there are lots of hits, I get the choice of printing the results to a file instead of displaying them. The script also lets me choose between seeing all records with any of the items (the OR case: A or B or...) or just the records containing all the searched-for items on one line (the AND case: A and B and...).

Read More...
 
Old 06-20-2014, 09:11 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,213

Rep: Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613Reputation: 1613
I wrote a shell script that does this as well:

Code:
grep 'pattern1\|pattern2\|pattern3\|pattern4' filename | wc -l; \
echo "print to screen or file?"; read I; if [ "$I" == "screen" ]; \
then  grep --color 'pattern1\|pattern2\|pattern3\|pattern4' filename; \
else grep 'pattern1\|pattern2\|pattern3\|pattern4' filename > output; fi
 
  


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
LibreOffice Writer: How to color single cell with multiple colors ghantauke Linux - General 1 09-21-2012 08:56 PM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
[SOLVED] Bash Scripting - Output as Multiple Files zer0signal Programming 14 01-26-2011 06:43 PM
bash scripting: using color in dialog dansku Programming 4 01-22-2010 08:16 AM
multiple color support in aterm ????? UsualTuxpect Linux - Software 6 08-27-2004 09:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - News > Syndicated Linux News

All times are GMT -5. The time now is 02:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration