Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to print the "grep" result as specified keyword order? Post 303037632 by RudiC on Thursday 8th of August 2019 08:47:53 AM
Old 08-08-2019
For reading the keywords from file, try grep -f id.txt


For keeping the sequence as given in id.txt, you could write e.g. an awk or perl script. Or try this very inefficient shell (untested):
Code:
while read ID
  do   grep $ID content.xls
  done < id.txt

Don't try with large files, as it scans through the entire content.xls for every single keyword in id.txt
Reading the content.xls file into an associated array indexed by the key value and then printing it according to the keys found in id.txt is left as an exercise for the reader.
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies

2. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

3. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

4. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

5. UNIX for Dummies Questions & Answers

Execute "find . -exec grep" in desending Order

Hi Xperts, I've one query for you. Please help me solving this. Below command is taking long time to fetch names of the files which contain string "475193976" because folder contains millions of files. I agree that this is what this function suppose to do. Correct.. But can it be possible... (6 Replies)
Discussion started by: gav_dhiman
6 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

8. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

9. Shell Programming and Scripting

sort, columns, no result! can I print files of "planes"?

hi, please can I ask you for some help? I have data from 3D situation, x y z value I'd like to use gnuplot to generate maps of the value in the planes z=0 to z=1 for example, my file looks like -0,012 0,0060 0,0 0,13972813076023477 -0,012 0,0064319163 4,2894483E-4 ... (1 Reply)
Discussion started by: kocour
1 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
Text::WordDiff::HTML(3pm)				User Contributed Perl Documentation				 Text::WordDiff::HTML(3pm)

Name
       Text::WordDiff::HTML - XHTML formatting for Text::WordDiff

Synopsis
	   use Text::WordDiff;

	   my $diff = word_diff 'file1.txt', 'file2.txt'; { STYLE => 'HTML' };
	   my $diff = word_diff $string1,   $string2,    { STYLE => 'HTML' };
	   my $diff = word_diff *FH1,	     *FH2,	   { STYLE => 'HTML' };
	   my $diff = word_diff &reader1,   &reader2,    { STYLE => 'HTML' };
	   my $diff = word_diff @records1,  @records2,   { STYLE => 'HTML' };

	   # May also mix input types:
	   my $diff = word_diff @records1,  'file_B.txt', { STYLE => 'HTML' };

Description
       This class subclasses Text::WordDiff::Base to provide a XHTML formatting for Text::WordDiff. See Term::WordDiff for usage details. This
       class should never be used directly.

       Text::WordDiff::HTML formats word diffs for viewing in a Web browser. The diff content is highlighted as follows:

       o   "<div class="file">"

	   This element contains the entire contents of the diff "file" returned by "word_diff()". All of the following elements are subsumed by
	   this one.

	   o   "<span class="fileheader">"

	       The header section for the files being "diff"ed, usually something like:

		 --- in.txt    Thu Sep	1 12:51:03 2005
		 +++ out.txt   Thu Sep	1 12:52:12 2005

	       This element immediately follows the opening "file" "<div>" element, but will not be present if Text::WordDif cannot deterimine the
	       file names for both files being compared.

	   o   "<span class="hunk">"

	       This element contains a single diff "hunk". Each hunk may contain the following elements:

	       o   "<ins>"

		   Inserted content.

	       o   "<del>"

		   Deleted content.

       You may do whatever you like with these elements and classes; I highly recommend that you style them using CSS. You'll find an example CSS
       file in the eg directory in the Text-WordDiff distribution.

See Also
       Text::WordDiff
       Text::WordDiff::ANSIColor

Support
       This module is stored in an open repository at the following address:

       <https://svn.kineticode.com/Text-WordDiff/trunk/>

       Patches against Text::WordDiff are welcome. Please send bug reports to <bug-text-worddiff@rt.cpan.org>.

Author
       David Wheeler <david@kineticode.com>

Copyright and License
       Copyright (c) 2005-2008 David Wheeler. Some Rights Reserved.

       This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

perl v5.10.0							    2009-09-24						 Text::WordDiff::HTML(3pm)
All times are GMT -4. The time now is 11:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy