Sponsored Content
Top Forums Shell Programming and Scripting Match first column entries precisely and fetch whatever in front of it Post 302732249 by Don Cragun on Saturday 17th of November 2012 03:33:28 AM
Old 11-17-2012
If first.txt didn't have trailing spaces on most lines, my first guess would have worked. But, with the files you attached, the awk program:
Code:
awk 'FNR == NR {f[$1]; next}
{       for(n = split($1, f1, ","); n > 0; n--)
                if(f1[n] in f) {
                        $1 = f1[n]
                        print
                }
}' first.txt FS="\t" OFS="\t" second.txt

produces the following output:
Code:
CTSD    Insulin recombinant     Novolin R (Novo Nordisk)        Approved        For treatment of Type I and II diabetes mellitus.
CTSD    Insulin, porcine        Iletin II       Approved        For the treatment of type I and II diabetes mellitus.
LCT     Vitamin C       Adenex  Approved        Used to treat vitamin C deficiency, scurvy, delayed wound and bone healing, urine acidification, and in general as an antioxidant. It has also been suggested to be an effective antiviral agent.
B4GALT1 N-Acetyl-D-glucosamine  Aflexa  Approved        For the treatment and prevention of osteoarthritis, by itself or in combination with chondroitin sulfate.
PPARD   Icosapent       Not Available   Approved        EPA can be used for lowering elevated triglycerides in those who are hyperglyceridemic. In addition, EPA may play a therapeutic role in patients with cystic fibrosis by reducing disease severity and may play a similar role in type 2 diabetics in slowing the progression of diabetic nephropathy.
NR3C1   Flunisolide     Aerobid Approved        For the maintenance treatment of asthma as a prophylactic therapy.
CHRM1   Cevimeline      Evoxac  Approved        For the treatment of symptoms of dry mouth in patients with Sjögren's Syndrome.

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

2. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

3. Shell Programming and Scripting

match sentence and word adn fetch similar words in alist

Hi all, I have ot match sentence list and word list anf fetch similar words in a separate file second file with 2 columns So I want the output shuld be 2 columns like this (3 Replies)
Discussion started by: manigrover
3 Replies

4. Shell Programming and Scripting

Match the word or words and fetch the entries

Hi all, I have 7 words Now I have 1 file which contain data in large number of rows and columns and 6th column contain any of these words or may be more than one words among above 7 words: I want script should search for the above mentioned 7 words in the 6th column ... (9 Replies)
Discussion started by: manigrover
9 Replies

5. Shell Programming and Scripting

Match words and fetch data in front of it in second column

Hi all, I have 2 files one file contain data like this in one column AST3 GSTY4 JST3 second file containign data like this in 2 columns AST3(PAXXX),GSTY4(PAXXY) it is used in diabetes KST4 it is used in blood... (6 Replies)
Discussion started by: manigrover
6 Replies

6. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Liberation Sans"; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

7. Shell Programming and Scripting

Find common and fetch what ever in front of it

Hi guys As my previous one is not working now I have a different problem with me one file with entries F2 F3 YUH SUH second fiel several columns like excel sheet (8-9) but my file in text F2 fgf gfhjhjghjghj dhgfhgfh 234324 F3 ... (6 Replies)
Discussion started by: Priyanka Chopra
6 Replies

8. Shell Programming and Scripting

Match columns and fetch whatever in front of it

Hi Solved these kind of issues using these codes But these are not wrking for my attached files can anybody check........ awk 'NR==FNR{X++;next}{if(X){print}}' file1 file2 awk 'NR==FNR{X=$0;next}{n=split($1,P," ");sub($1,"",$0);for(i=1;i<=n;i++){if(X]){print P,$0}}}' file1 FS="\t" file2 ... (6 Replies)
Discussion started by: Priyanka Chopra
6 Replies

9. Shell Programming and Scripting

Match first column and separate entries

Hi I have 2 big files containing following information: file 1 12345 345634 217341 87234693 8236493 file 2: 12345 1237 (6 Replies)
Discussion started by: kaav06
6 Replies

10. Shell Programming and Scripting

How to dynamically fetch lines after a match?

Hi Friends, How to fetch current hour data from a log file, given below? I want all lines after the match "Wed Aug 13 16:" I have tried below command, but not working. If I put exact string, then it is working. cat /iscp/user/monitor/ORA_errors |awk '/`date +%h" "%d" "%h`/,printed==999 {... (7 Replies)
Discussion started by: suresh3566
7 Replies
CVS-MAILCOMMIT(1)						 Debian GNU/Linux						 CVS-MAILCOMMIT(1)

NAME
cvs-mailcommit - Send CVS commitments via mail SYNOPSIS
cvs-mailcommit [options] [version*] DESCRIPTION
cvs-mailcommit is a helper application to CVS to help people keep track of CVS repositories via mail. It is hooked into the CVS system via the CVSROOT/loginfo file. It will read modification information from CVS via stdin and require version information via the commandline. cvs-mailcommit will send differences of modified files or entire new files via mail to the denoted address. You'll have to hook it into CVS for each module in a repository that you want to monitor via mail. See INSTALLATION below OPTIONS
This program supports the following arguments. When the arguments don't make sense the program won't do anything. -m address, --mailto address Send the mail to the specified address. This option can be specified on the commandline multiple times. --diff Generate unified diffs for all modified files. --full Include the entire fill for newly created files that were added to the repository. --maxlines nnn You can specify how many lines per file may be quoted in the resulting mail. Limiting the number of quoted lines may be useful for repositories with excessive changes that are similar. The default is to copy 400 lines. --xloop address Include a special X-Loop header in the generated mail. This is intended for users to be able to filter CVS mails by a common header line. The line will look like X-Loop: address --from address Generate a From:-line of the form From: CVS User foo <address> Otherwise the local user the program runs under will be used instead of address. With this parameter you can ensure that all such mails will be sent with the same from line, which may be useful for moderated lists or some where only subscribers may write. --replyto address Try to redirect replies to CVS mails to another address by setting proper header lines such as Reply-To: address Mail-Followup-To: address --approved address Include a special Approved:-line in the mail. This header is intended for moderated mailing-lists to pass the SmartList moderation mechanism. The created header will look like Approved: address --cvs version string This option carries the CVS version info from CVS into the program. It will be added automatically by CVS. When installing this program into the loginfo file of a CVS repository, you will need to add the following option: --cvs %{sVv} If you want to test this program manually you'll have to supply the module directory and the modified files including the old and new versions. This will look like --cvs 'CVSROOT loginfo,1.1,1.2' This option is only usful for old-style CVS format strings (i.e. prior to CVS 1.12.6). You can continue using old-style format strings with newer cvs if you write %1{sVv} and set UseNewInfoFmtStrings=yes in CVSROOT/config. For more recent versions of CVS you should, however, use the new --root and --dir arguments and place %{sVv} at the end of the commandline. --root cvs repository Specify the CVS repository directory. This is normally done by the CVS server. Prior to version 1.12 the repository was transmitted to the log processor via the CVSROOT environment variable. The parameter to this option is normally filled in by CVS using the %r format string: --root %r --dir module directory Specify the directory within the CVS repository in which directories or file were added or modified. The parameter to this option is normally filled in by CVS using the %p format string: --dir %p CONFIGURATION FILE
cvs-mailcommit supports an additional configuration file /etc/cvs-mailcommit.pl so that hard-coded default values can be overwritten. The file is included via require and hence needs to contain valid Perl code, which evaluates to true. I.e. place 1; at the end of the file. INSTALLATION
The CVSROOT/loginfo file controls where cvs commit log information is sent. The first entry on a line is a regular expression which must match the directory (alias module) that the change is being made to, relative to the $CVSROOT. If a match is found, then the remainder of the line is a filter program that should expect log information on its standard input. A loginfo line looks like <directory> <command> --<option> --<option> NOTES
The --cvs option is only valid for old-style CVS format strings prior to version 1.12.6 of CVS with %{sVv} or for new-style CVS format strings using the compatibility hack with %1{sVv}. For new-style CVS format strings for CVS version 1.12.6 or higher --cvs must not be used anymore, but instead --root and --dir are required. The version information %{sVv} must be added at the end of the command line. EXAMPLE
Assume you want to monitor changes in the CVSROOT module, then you may want to use the following line. CVSROOT cvs-mailcommit --mailto master@host.org --from cvs@cvshost.com --cvs %{sVv} --diff --full If you want to distribute changes in a module via a mailing list where only these log messages should appear you may have to add an X-Loop: or Approved: header line. webwml cvs-mailcommit --mailto master@host.org --from cvs@cvshost.com --approved cvsmaster@cvshost.com --cvs %{sVv} --diff --full The above configuration lines are valid only for old-style format strings. With a more recent version of CVS (1.12.6 or newer) you'll have to replace %{sVv} with %1{sVv} and set UseNewInfoFmtStrings to yes in CVSROOT/config. For new-style CVS format strings other parameters need to be used since CVS changed the syntax and semantics. You must not use the --cvs option anymore but need to use --root and --dir and place the version list at the end. The last example converted for new-style format strings looks like the following: webwml cvs-mailcommit --mailto master@host.org --from cvs@cvshost.com --approved cvsmaster@cvshost.com --diff --full --root %r --dir %p %{sVv} To improve readability, the above lines were broken up into several lines using normal continuation lines. This is not supported by CVS. You will have to write it in one single line. WARNING
CVS does not support continuation lines (multiple lines per command) in the CVSROOT/loginfo file. You'll have to write each filter in a single line of its own. SOURCE
http://www.infodrom.org/Infodrom/tools/cvs-mailcommit.html Debian Project 2004-08-09 CVS-MAILCOMMIT(1)
All times are GMT -4. The time now is 04:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy