Sponsored Content
Top Forums Shell Programming and Scripting Script to match a pattern and print only the pattern and after that Post 302773691 by RudiC on Thursday 28th of February 2013 01:41:23 PM
Old 02-28-2013
Try
Code:
awk     'NR==1  {n = split (items, IT)}                 # put the items to search for into array IT
                {for (i=1; i<NF; i++)                   # check every single field in actual line
                   for (j=1; j<=n; j++)                 # against the items wanted
                     if ($i == IT[j]) VL[j]=$(++i)      # if found, register value (= next field) in array VL, and skip check on value
                }
         VL[1]==VL[2]   {print VL[3]}                   # if values of first two items match, print value of third
        ' items="xyz: abz: qrt:" file
[2312]

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to match a pattern and print lines

Hi I have a file (say 'file1')and I want to search for a first occurence of pattern (say 'ERROR') and print ten lines in the file below pattern. I have to code it in PERL and I am using Solaris 5.9. I appreciate any help with code Thanks Ammu (6 Replies)
Discussion started by: ammu
6 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Match pattern in a field, print pattern only instead of the entire field

Hi ! I have a tab-delimited file, file.tab: Column1 Column2 Column3 aaaaaaaaaa bbtomatoesbbbbbb cccccccccc ddddddddd eeeeappleseeeeeeeee ffffffffffffff ggggggggg hhhhhhtomatoeshhh iiiiiiiiiiiiiiii ... (18 Replies)
Discussion started by: lucasvs
18 Replies

4. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

5. Shell Programming and Scripting

Script to compare pattern and print a different pattern in each line

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ......qrt: .... .......xyz: abz: ......qrt: ... I have tried using awk and cut, but the position of these values keep changing, so I wasn't able to get... (2 Replies)
Discussion started by: Serena
2 Replies

6. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

7. Shell Programming and Scripting

Print only next pattern in a line after a pattern match

I have 2013-06-11 23:55:14 1Umexd-0004cm-IG <= user@domain.com I need sed/awk operation on this, so that it should print the very next pattern only after the the pattern mach <= ie only print user@domain.com (7 Replies)
Discussion started by: anil510
7 Replies

8. Shell Programming and Scripting

Print only match pattern

Hi, I want to print the lines from file1 which has the matching pattern from file2 in linux. file1 data is below ----------------- CACA|1234 CA|2345 file2 data is below ----------------- CA NC TX Now I want to print the lines from file1 for the values present in file2. ... (5 Replies)
Discussion started by: ureddy
5 Replies

9. 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

10. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies
XmListReplacePositions(3X)												XmListReplacePositions(3X)

NAME
XmListReplacePositions - A List function that replaces items in a list based on position SYNOPSIS
#include <Xm/List.h> void XmListReplacePositions (widget, position_list, item_list, item_count) Widget widget; int *position_list; XmString *item_list; int item_count; DESCRIPTION
XmListReplacePositions replaces noncontiguous items in a list. The item at each position specified in position_list is replaced with the corresponding entry in item_list. When the items are inserted into the list, they are compared with the current XmNselectedItems list. Any of the new items that match items on the selected list appears selected. A warning message is displayed if a specified position is invalid; that is, the value is 0, a negative integer, or a number greater than the number of items in the list. Specifies the ID of the List widget. Specifies an array of the positions of items to be replaced. The position of the first item in the list is 1; the position of the second item is 2; and so on. Specifies an array of the replacement items. Specifies the number of elements in position_list and item_list. This number must be non-negative. For a complete definition of List and its associated resources, see XmList(3X). SEE ALSO
XmList(3X) XmListReplacePositions(3X)
All times are GMT -4. The time now is 07:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy