Multiple pattern match and print the output in a single line
I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched,
finally need to print these three values in a single line.
Sample Log:
I tried in the below way but this was not working.
Kindly help
I have a file nbu_faq.txt (Question/answer) which looks like this
What I am trying to do is write out each question in a file1.txt and than the question/answer in a file2.txt
like this
file1.txt
Q: What is nbu?
Q: What is blablabla...?
Q: Why ....?
file2.txt
Q: What is nbu?
A:... (4 Replies)
Hi,
Please suggest, how to get the output of below script in single line, its giving me in different lines
______________________
#!/bin/ksh
export Path="/abc/def/ghi";
Home="/home/psingh/prat";
cd $Path;
find $Path -name "*.C#*" -newer "abc.C#1234" -print > $Home
cat $Home | while... (1 Reply)
Hi,
I have a xml file
<cisco:name>
<cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm>
<cisco:meNm>10.1.100.19</cisco:meNm>
<cisco:ehNm>/shelf=1</cisco:ehNm>
<cisco:subname>
<cisco:meNm>10.1.100.19</cisco:meNm>
<cisco:sptp>Cisco PortA Series</cisco:sptp>
... (11 Replies)
Dear All,
Hv a very specific requirement.
I have a very large text file and in which I have to match a pattern and insert a line above and below.
Eg:
My file
cat test
date1
date2
date3
date4
I need to match 'date3' and insert "Reminder1" above date3 and insert 'reminder2'... (4 Replies)
Data:
Pattern Data Data Data
Data Data Data
Data Data Data
...
With awk, how do I print the pattern matching line, then the subsequent lines following the pattern matching line. Varying number of lines following the pattern matching line. (9 Replies)
here is what i want to achieve.. i have a file with below contents
cat fileName
blah blah blah
.
.DROP this
REJECT that
.
--sport 7800 -j REJECT --reject-with icmp-port-unreachable
--dport 7800 -j REJECT --reject-with icmp-port-unreachable
.
.
.
more blah blah blah
--dport 3306... (14 Replies)
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)
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)
example of problem:
when I echo "$e" >> /home/cogiz/file.txt
result prints to file as:AA
BB
CC
I need it to save to file as this:AA BB CC
I know it's probably something really simple but any help would be greatly appreciated.
Thank You.
Cogiz (7 Replies)
Hi All,
Greetings!
I have a file of 40000+ lines with different entries, I need matching entries filterd out to their files based on first filed pattern for the matching :
For example:
All server1 entries (in field1) to come together with its path in 2nd field.
The best output I want... (9 Replies)
Discussion started by: rveri
9 Replies
LEARN ABOUT REDHAT
switch
switch(n) Tcl Built-In Commands switch(n)
__________________________________________________________________________________________________________________________________________________NAME
switch - Evaluate one of several scripts, depending on a given value
SYNOPSIS
switch ?options? string pattern body ?pattern body ...?
switch ?options? string {pattern body ?pattern body ...?}
_________________________________________________________________DESCRIPTION
The switch command matches its string argument against each of the pattern arguments in order. As soon as it finds a pattern that matches
string it evaluates the following body argument by passing it recursively to the Tcl interpreter and returns the result of that evaluation.
If the last pattern argument is default then it matches anything. If no pattern argument matches string and no default is given, then the
switch command returns an empty string.
If the initial arguments to switch start with - then they are treated as options. The following options are currently supported:
-exact Use exact matching when comparing string to a pattern. This is the default.
-glob When matching string to the patterns, use glob-style matching (i.e. the same as implemented by the string match command).
-regexp When matching string to the patterns, use regular expression matching (as described in the re_syntax reference page).
-- Marks the end of options. The argument following this one will be treated as string even if it starts with a -.
Two syntaxes are provided for the pattern and body arguments. The first uses a separate argument for each of the patterns and commands;
this form is convenient if substitutions are desired on some of the patterns or commands. The second form places all of the patterns and
commands together into a single argument; the argument must have proper list structure, with the elements of the list being the patterns
and commands. The second form makes it easy to construct multi-line switch commands, since the braces around the whole list make it unnec-
essary to include a backslash at the end of each line. Since the pattern arguments are in braces in the second form, no command or vari-
able substitutions are performed on them; this makes the behavior of the second form different than the first form in some cases.
If a body is specified as ``-'' it means that the body for the next pattern should also be used as the body for this pattern (if the next
pattern also has a body of ``-'' then the body after that is used, and so on). This feature makes it possible to share a single body among
several patterns.
Beware of how you place comments in switch commands. Comments should only be placed inside the execution body of one of the patterns, and
not intermingled with the patterns.
Below are some examples of switch commands:
switch abc a - b {format 1} abc {format 2} default {format 3}
will return 2,
switch -regexp aaab {
^a.*b$ -
b {format 1}
a* {format 2}
default {format 3}
}
will return 1, and
switch xyz {
a
-
b
{
# Correct Comment Placement
format 1
}
a*
{format 2}
default
{format 3}
}
will return 3.
SEE ALSO
for(n), if(n), regexp(n)
KEYWORDS
switch, match, regular expression
Tcl 7.0 switch(n)