01-17-2013
Match pattern and get lines numbers in a vector
Hi everyone,
I am new to shell scripting, and would appreciate your help on following problem.
I need to search a file for a pattern, then get the number of each line that matches the given pattern.
Then I need to search those specific line numbers from the first file in a second file and print the entire lines.
I tried with grep -n 'pattern' from the first file, which gives me:
21: pattern
37: pattern
58: pattern
...
now I need to get 21,37,58... in a vector or something, and display these lines from the second file.
I hope I made myself clear.
thanks in advance
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Dear experts,
i want to search pattern tre and copy this line and above two lines
in a seperate file::
Thanks for the help
SEV="MAJOR": RX-TX HW-FAILURE DOMAIN="alcomc2_BSS_20
unit-type % bts nbr % 24
SBL-type % tre nbr % 4 subnb % 255
BR,
Danish (16 Replies)
Discussion started by: Danish Shakil
16 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I would like to know how can I get lines from a text file that match no more than 2 '>'. Example:
Input file:
a >cr1 4 a>b b>c
a >cr2 5 a>b
Output file:
a >cr2 5 a>b
Thanks in advance (2 Replies)
Discussion started by: fadista
2 Replies
3. Shell Programming and Scripting
I am using Solaris, I want to print
3 lines before pattern match
pattern
5 lines after pattern match
Pattern is abcd to be searched in a.txt. Looking for the solution in sed/awk/perl. Thanks ..
Input File a.txt:
=================
1
2
3
abcd
4
5
6
7
8 (7 Replies)
Discussion started by: manuswami
7 Replies
4. Shell Programming and Scripting
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
I have a file of 1.3 millions lines.
some are with the same word twice on the line, some line have two diffrent words.
each line has two words, one in brackets.
example:
foo (foo)
bar (bar)
thae (awvd)
beladf (vswvw)
I am sure this can be done with one line of... (6 Replies)
Discussion started by: robsonde
6 Replies
6. Shell Programming and Scripting
I need to print the lines that do not match a pattern. I tried using grep -v and sed -n '/pattern/!p', but both of them are not working as I am passing the pattern as variable and it can be null some times.
Example
........ abcd......
.........abcd......
.........abcd......... (4 Replies)
Discussion started by: sunny1234
4 Replies
7. Shell Programming and Scripting
Hi Experts,
I am finding difficulty to get exact match:
file
OPERATING_SYSTEM=HP-UX
LOOPBACK_ADDRESS=127.0.0.1
INTERFACE_NAME="lan3"
IP_ADDRESS="10.53.52.241"
SUBNET_MASK="255.255.255.192"
BROADCAST_ADDRESS=""
INTERFACE_STATE=""
DHCP_ENABLE=0
INTERFACE_NAME="lan3:1"... (6 Replies)
Discussion started by: rveri
6 Replies
8. Shell Programming and Scripting
Hi all,
I got a file that contains the following content, Actually it is a part of the file content,
Installing XYZ XYZA Image, API 18, revision 2
Unzipping XYZ XYZA Image, API 18, revision 2 (1%)
Unzipping XYZ XYZA Image, API 18, revision 2 (96%)
Unzipping XYZ XYZA Image, API 18,... (7 Replies)
Discussion started by: Kashyap
7 Replies
9. Shell Programming and Scripting
Hi, i have a big file having many opcodes.
if (opcode="01110000000100000000" ) then --fadd
result.opcode := "01110000000100000000";
result.s0 := '1';
result.s1 := '1';
result.s2 := '0';
result.inst := '0';
result.scalar := '1';... (7 Replies)
Discussion started by: twistedpair
7 Replies
10. Shell Programming and Scripting
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
LEARN ABOUT MOJAVE
tcl_stringmatch
Tcl_StringMatch(3) Tcl Library Procedures Tcl_StringMatch(3)
__________________________________________________________________________________________________________________________________________________
NAME
Tcl_StringMatch, Tcl_StringCaseMatch - test whether a string matches a pattern
SYNOPSIS
#include <tcl.h>
int
Tcl_StringMatch(str, pattern)
int
Tcl_StringCaseMatch(str, pattern, flags)
ARGUMENTS
const char *str (in) String to test.
const char *pattern (in) Pattern to match against string. May contain special characters from the set *?[].
int flags (in) OR-ed combination of match flags, currently only TCL_MATCH_NOCASE. 0 specifies a case-sensitive search.
_________________________________________________________________
DESCRIPTION
This utility procedure determines whether a string matches a given pattern. If it does, then Tcl_StringMatch returns 1. Otherwise
Tcl_StringMatch returns 0. The algorithm used for matching is the same algorithm used in the string match Tcl command and is similar to
the algorithm used by the C-shell for file name matching; see the Tcl manual entry for details.
In Tcl_StringCaseMatch, the algorithm is the same, but you have the option to make the matching case-insensitive. If you choose this (by
passing TCL_MATCH_NOCASE), then the string and pattern are essentially matched in the lower case.
KEYWORDS
match, pattern, string
Tcl 8.5 Tcl_StringMatch(3)