Sponsored Content
Top Forums Shell Programming and Scripting awk regexp to print repetitive pattern Post 302977383 by RudiC on Sunday 17th of July 2016 06:02:00 AM
Old 07-17-2016
Adding a varying number of fields to an incomplete line might be achieved like
Code:
awk '
NR == FNR       {A[$2] = $0
                  next
                }
!A[$1]          {A[$1] = sprintf ("%*s", 14-NF, "-")
                 gsub (/ /, "-\t", A[$1])
                }
                {print $0, A[$1]
                }
' file2 file1 
TCONS_00000001    W5GKA3_WHEAT XLOC_000001 TCONS_00000001 LOC_Os02g39790.2 47.273 55 24 2 3855 4016 335 385 3.60e-04  
TCONS_00000002    W5GKA3_WHEAT XLOC_000001 TCONS_00000002 LOC_Os02g39790.2 47.273 55 24 2 2368 2529 335 385 2.35e-04  
TCONS_00000011    I1IBH3_BRADI XLOC_000001 TCONS_00000011 LOC_Os02g39790.2 47.273 55 24 2 2200 2361 335 385 2.28e-04   
TCONS_00000009    W5GKA3_WHEAT XLOC_000001 TCONS_00000009 LOC_Os02g39790.2 47.273 55 24 2 5083 5244 335 385 2.83e-04  
TCONS_00000005    I1IBH3_BRADI -	-	-	-	-	-	-	-	-	-	-	-
TCONS_00000006    I1IBH3_BRADI -	-	-	-	-	-	-	-	-	-	-	-
TCONS_00000007    W5GKA3_WHEAT XLOC_000001 TCONS_00000007 LOC_Os02g39790.2 47.273 55 24 2 3553 3714 335 385 3.09e-04


EDIT: Or just use a for loop...




.

Last edited by RudiC; 07-17-2016 at 07:18 AM..
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk how to print if the search pattern contains speace

the data file is as below: > cat master.cnf /usr| location for usr|5 /src/ver1| version 1 |10 /src/ver2/log| ver 2 log |25 /src/sys/apps/log| Application log for sys|36 /src/sys/apps/conf| configuration location for app|45 /src/sys/apps/bin| binary location app|55my script is as below: ... (1 Reply)
Discussion started by: McLan
1 Replies

2. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

3. Shell Programming and Scripting

Perl Repetitive Pattern Matching

Problem: GIVEN ======= my $sql="INSERT INTO table_nm(a, b, b, d, e, f , g) VALUES (2046, TODAY, 'Change Subscription Name', '00000000000002000000000000000000000000000000000000', '00000000000001000000000000000000000000000000000000', '00000000000000000000000000000000000000000000000000', 1);... (2 Replies)
Discussion started by: Niroj
2 Replies

4. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies

5. Shell Programming and Scripting

Print lines between two repetitive patterns

Hi users I have one file which has number of occurrence of one pattern examples Adjustmenttype,11 xyz 10 dwe 9 abd 13 def 14 Adjustmenttype,11 xyz 24 dwe 34 abd 35 def 11 nmb 12 Adjustmenttype, not eleven .... ... ... (2 Replies)
Discussion started by: eranmoh
2 Replies

6. Shell Programming and Scripting

print pattern between two variables awk sed

I am trying to print text between two variables in a file I have tried the following things but none seem to work: awk ' /'$a'/ {flag=1;next} /'$b'/{flag=0} flag { print }' file and also sed "/$a/,/$b/p" file But none seem to work Any Ideas? Thanks in Advance (5 Replies)
Discussion started by: forumbaba
5 Replies

7. Shell Programming and Scripting

AWK: Grep Pattern and print help

I wanted to get outcome from a big file with pattern quoted: Line FSP LSP SR RL Test1 100 300 4 4000 Test2 1 300 2 300 Any help is greatly appreciated. Thank you. (15 Replies)
Discussion started by: rtsiahaan
15 Replies

8. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

9. Shell Programming and Scripting

Help with using awk to print pattern/occurence

Hi, Do anybody know how to use awk to count the pattern at specific column? Input file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a . . Output file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a 3 . . I plan to count how many "miR" in column 3... (2 Replies)
Discussion started by: cpp_beginner
2 Replies

10. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies
shevek::regexp(3)					     Library Functions Manual						 shevek::regexp(3)

NAME
shevek::regexp - Use regular expressions. SYNOPSIS
#include <regexp.hh> Public Member Functions regexp (std::string const &pattern=std::string(), bool case_sensitive=false) Create a new object, and optionally fill it with a pattern. regexp & operator= (std::string const &pattern) Set a pattern, removing the previous one. regexp (regexp const &that) Copy a regexp. regexp & operator= (regexp const &that) Copy a regexp. void case_sensitive (bool value=true) Set whether the evaluation should be case sensitive. ~regexp () Destructor, this cleans up internal structures. bool operator() (std::string const &data) Check whether the pattern matches a string, and fill internal match structures if it does. std::string operator[] (unsigned idx) const Retrieve the value of a subexpression from the last matched string. bool valid (unsigned idx) const Test whether a subexpression was filled by the last matching string. unsigned size () const Get the number of subexpression. std::string transform (std::string const &data) const Transform a string with -codes according to the last matching string. std::string const & pattern () const Get the current pattern. Detailed Description Use regular expressions. Member Function Documentation std::string shevek::regexp::operator[] (unsignedidx) const Retrieve the value of a subexpression from the last matched string. This throws an exception if the subexpression is not valid. Author Generated automatically by Doxygen for libshevek from the source code. libshevek Fri May 11 2012 shevek::regexp(3)
All times are GMT -4. The time now is 10:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy