Sponsored Content
Top Forums UNIX for Dummies Questions & Answers print multiple lines from text file based on pattern list Post 302555416 by Oyster on Wednesday 14th of September 2011 04:41:04 PM
Old 09-14-2011
print multiple lines from text file based on pattern list

I have a text file with a list of items/patterns:

ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig12238
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig34624
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig56875
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig70306
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig71435
...

I would like to print those lines which match from a tab-delimited file containing many many more lines:

...
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig60558 1086
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig60559 641 95 14.038 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig60559 731
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig60560 620 1406 245.247 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig60560 625
ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig60561 609 208 36.771
...

Can grep process a pattern file? It seems as if it should, however, I have not had success. sed, awk? Please help. Thanks.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge lines in text file based on pattern

Hello, I have searched forum trying to find a solution to my problem, but could not find anything or I did not understand the examples.... I should say, I am very inexperienced with text processing. I have a text file with approx 60k lines in it. I need to merge lines based on the number... (8 Replies)
Discussion started by: Bertik
8 Replies

2. Shell Programming and Scripting

Awk: print lines with one of multiple pattern in the same field (column)

Hi all, I am new to using awk and am quickly discovering what a powerful pattern-recognition tool it is. However, I have what seems like a fairly basic task that I just can't figure out how to perform in one line. I want awk to find and print all the lines in which one of multiple patterns (e.g.... (8 Replies)
Discussion started by: elgo4
8 Replies

3. Shell Programming and Scripting

Split a text file into multiple pages based on pattern

Hi, I have a text file (attached the sample). I have also, attached the way the way the files need to be split. We get this file, that will either have 24 Jurisdictions, or will miss some and retain some. Like in the attached sample file, there are only Jurisdictions 03,11,14,15, 20 and 30.... (3 Replies)
Discussion started by: ebsus
3 Replies

4. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

5. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

6. Shell Programming and Scripting

awk to print lines based on text in field and value in two additional fields

In the awk below I am trying to print the entire line, along with the header row, if $2 is SNV or MNV or INDEL. If that condition is met or is true, and $3 is less than or equal to 0.05, then in $7 the sub pattern :GMAF= is found and the value after the = sign is checked. If that value is less than... (0 Replies)
Discussion started by: cmccabe
0 Replies

7. UNIX for Beginners Questions & Answers

UNIX script to append multiple text files into one file based on pattern present in filaname

Hi All-I am new to Unix , I need to write a script. Can someone help me with a requirement where I have list of files in a directory, I want to Merge the files if a pattern of string matches in filenames? AAAL_555A_ORANGE1_F190404.TXT AAAL_555A_ORANGE2_F190404.TXT AAAL_555A_ORANGE3_F190404.TXT... (6 Replies)
Discussion started by: Shankar455
6 Replies

8. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

9. UNIX for Beginners Questions & Answers

Reading a file line by line and print required lines based on pattern

Hi All, i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field. i am using centos 7 Operating system. want to read below file. # cat /tmp/d5 NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies
SWISS::TextFunc(3pm)					User Contributed Perl Documentation				      SWISS::TextFunc(3pm)

NAME
SWISS::TextFunc DESCRIPTION
This module is designed to be a repository of functions that are repeatedly used during parsing and formatting of SWISS-PROT/TREMBL lines. If more than two line types need to do aproximately the same thing then it is probably in here. All functions expect to be called as package->function(param list) listFromText Takes a piece of text, a seperator regex and a seperator that may appear at the end. Returns an array of items that were seperated in the text by that seperator. Takes care of null items (looses them for you). textFromList Takes an array of items, a separator, a terminating string, and a line width. Returns an array of strings, each ending with the separator or the terminator with a width less than or equal to the width specified. Seems to do the wrong thing for references - not sure why. Don't use it for that. wrapText Takes a string and a length. Returns an array of strings which are shorter or equal in length to length, spliting the string on white space. wrapOn ($firstLinePrefix, $linePrefix, $colums, $text[, @separators]) Wraps $text into lines with at most $colums colums. Prepends the prefixes to the lines. @separators is a list of expressions on which to wrap. The expression itself is part of the upper line. If no @separators are provided, the $text is wrapped at whitespace except in EC/TC numbers or at dashes that separate words. First tries to wrap on the first item of @separators, then the next etc. If no wrap on any element of @separators or whitespaces is possible, wraps into lines of exactly length $colums. A special case is that the first item of @separators may be a reference to an array. This is used internally for wrapping FT VARIANT- like lines. Example: wrapOn('DE ', 'DE ', 40, '14-3-3 PROTEIN BETA/ALPHA (PROTEIN KINASE C INHIBITOR PROTEIN-1)', 's+') returns ['14-3-3 PROTEIN BETA/ALPHA (PROTEIN ', 'KINASE C INHIBITOR PROTEIN-1)'] wrapOn('DE ', 'DE ', 40, '14-3-3 PROTEIN BETA/ALPHA (PROTEIN KINASE C INHIBITOR PROTEIN-1)', ' (?=()', 's+') returns ['14-3-3 PROTEIN BETA/ALPHA ', '(PROTEIN KINASE C INHIBITOR PROTEIN-1)'] cleanLine Remove the leading line Identifier and three blanks and trailing spaces from an SP line. joinWith ($text, $with, $noAddAfter, @list) Concatenates $text and @list into one string. Adds $with between the original elements, unless the postfix of the current string is $noAddAfter. This is used to avoid inserting blanks after hyphens during concatenation. So unpleasant strings like 'CALMODULIN- DEPENDENT' are avoided. Unfortunately a correct reassembly of strings like 'CARBON-DIOXIDE' is not done. insertLineGroup ($textRef, $text, $pattern) Inserts text block $text into the text referred to by $textRef. $text will replace the text block in $textRef matched by $pattern. uniqueList (@list) Returns a list in which all duplicates from @list have been removed. currentSpDate returns the current date in SWISS-PROT format toMixedCase($text, @regexps) Convert a text to mixed case, according to one or more regular expressions. In scalar context, returns the new text; in array context, also returns the regexp with which the change was performed, or undef on failure. See corresponding item in SWISS::GN for more details. perl v5.10.1 2006-08-31 SWISS::TextFunc(3pm)
All times are GMT -4. The time now is 03:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy