Sponsored Content
Top Forums Shell Programming and Scripting Compare between current and next line and print Post 302937605 by jaydeep_sadaria on Friday 6th of March 2015 01:11:48 PM
Old 03-06-2015
Compare between current and next line and print

Dear All

I want below to compare two Consecutive line(i.e. current and next line). Based in that i need OP. Below is the IP file in that in i find "M" and if in next line i find "*" then i need both line in single line. If i dont find "*" in next line then i need to put commend "DOWN" .

I am using below script but its not print all line. Its ommite some line. Kindly suggest changes.

Script i am using:

Code:
{
if ($3 =="M") {
a=$0;
	{
		getline;
		b=$2;
	if ($3 =="*") {
		print a" "b;
			}
		 else {
		print a " down";
		}
	
}}
}


Code:
IP FILE:

2015-02-28 10:10:17 M KDA003X
2015-02-28 10:12:06 * KDA003X
2015-02-28 10:16:50 M KDA003X
2015-02-28 10:10:17 M KDA003Y
2015-02-28 10:12:06 * KDA003Y
2015-02-28 10:16:50 M KDA003Y
2015-02-28 10:10:17 M KDA003Z
2015-02-28 10:12:06 * KDA003Z
2015-02-28 10:16:50 M KDA003Z
2015-02-28 10:10:15 M RTE001X
2015-02-28 10:12:06 * RTE001X
2015-02-28 10:16:50 M RTE001X
2015-02-28 10:18:30 * RTE001X
2015-02-28 10:10:15 M RTE001Y
2015-02-28 10:12:06 * RTE001Y
2015-02-28 10:16:50 M RTE001Y
2015-02-28 10:18:30 * RTE001Y
2015-02-28 10:10:15 M RTE001Z
2015-02-28 10:12:06 * RTE001Z
2015-02-28 10:16:50 M RTE001Z
2015-02-28 10:18:30 * RTE001Z

Code:
OP NEEDED:
2015-02-28 10:10:17 M KDA003X 2015-02-28 10:12:06 * KDA003X
2015-02-28 10:16:50 M KDA003X DOWN
2015-02-28 10:10:17 M KDA003Y 2015-02-28 10:12:06 * KDA003Y
2015-02-28 10:16:50 M KDA003Y DOWN
2015-02-28 10:10:17 M KDA003Z 2015-02-28 10:12:06 * KDA003Z
2015-02-28 10:16:50 M KDA003Z DOWN
2015-02-28 10:10:15 M RTE001X 2015-02-28 10:12:06 * RTE001X
2015-02-28 10:16:50 M RTE001X 2015-02-28 10:18:30 * RTE001X
2015-02-28 10:10:15 M RTE001Y 2015-02-28 10:12:06 * RTE001Y
2015-02-28 10:16:50 M RTE001Y 2015-02-28 10:18:30 * RTE001Y
2015-02-28 10:10:15 M RTE001Z 2015-02-28 10:12:06 * RTE001Z
2015-02-28 10:16:50 M RTE001Z 2015-02-28 10:18:30 * RTE001Z

Script i am using:

Code:
{
if ($3 =="M") {
a=$0;
	{
		getline;
		b=$2;
	if ($3 =="*") {
		print a" "b;
			}
		 else {
		print a " down";
		}
	
}}
}


Thanks in advance.

Rgards
Jaydeep Sadaria
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print previous, current and next line using sed

Hi, how can i print the previous, current and next line using sed? current line is the matching line. The following prints all lines containing 'Failure' and also the immediate next line cat $file | sed -n -e '/Failure/{N;p;}' Now, i also want to print the previous line too. Thanks,... (8 Replies)
Discussion started by: ysrinu
8 Replies

2. Shell Programming and Scripting

Compare multiple fields in file1 to file2 and print line and next line

Hello, I have two files that I need to compare and print out the line from file2 that has the first 6 fields matching the first 6 fields in file1. Complicating this are the following restrictions 1. file1 is only a few thousand lines at most and file2 is greater than 2 million 2. I need to... (7 Replies)
Discussion started by: gillesc_mac
7 Replies

3. Shell Programming and Scripting

awk print the next line on the current line

Ok I have a file with hundreds of lines, four columns, space delimited, TESTB.TXT for example TESTB.TXT --- AA ZZ 12 34 BB YY 56 78 CC XX 91 23 DD VV 45 67 --- I want a new file that has 7 columns, the first four are identical, and the next 3 are the last three of the next line...so... (5 Replies)
Discussion started by: ajp7701
5 Replies

4. Shell Programming and Scripting

How to use sed to search for string and Print previous two lines and current line

Hello, Can anybody help me to correct my sed syntax to find the string and print previous two lines and current line and next one line. i am using string as "testing" netstat -v | sed -n -e '/test/{x;2!p;g;$!N;p;D;}' -e h i am able to get the previous line current line next line but... (1 Reply)
Discussion started by: nmadhuhb
1 Replies

5. Shell Programming and Scripting

Compare two file and print same line

i want to compare two file and print same line file1 12345 a 23456 a 45678 a 45679 a file2 23456 a 34567 a 45679 a output 23456 a 45679 a any one can help me? Thank you (7 Replies)
Discussion started by: bleach8578
7 Replies

6. Shell Programming and Scripting

Compare selected columns of two files and print whole line with mismatch

hi! i researched about comparing two columns here and got an answer. but after examining my two files, i found out that the first columns of the two files are not unique with each other. all i want to compare is the 2nd and 3rd column. FILE 1: ABS 456 315 EBS 923 163 JYQ3 654 237 FILE 2:... (1 Reply)
Discussion started by: engr.jay
1 Replies

7. UNIX for Dummies Questions & Answers

Awk to print data from current and previous line

Hi guys, I have found your forum super useful. However, right now I am stuck on a seemingly "simple" thing in AWK. I have two columns of data, the first column in Age (in million years) and the second column is Convergence Rate (in mm/yr). I am trying to process my data so I can use it to... (2 Replies)
Discussion started by: awk_noob_456
2 Replies

8. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

9. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

10. Shell Programming and Scripting

Tput cup, print on current line?

Heyas I'm thinking about a new approach for my core display, basicly as it should make aligments easier. Issue i'm currently facing, is tput cup capable of printing on the current line? My best achievements were: :) tui $ tput cup - 60;echo " ------ testing" ------ testing... (5 Replies)
Discussion started by: sea
5 Replies
MMROFF(1)						      General Commands Manual							 MMROFF(1)

NAME
mmroff - reference preprocessor SYNOPSIS
mmroff [ -x ] groff_arguments DESCRIPTION
mmroff is a simple preprocessor for groff, it is used for expanding references in mm, see groff_mm(7). groff is executed twice, first with -z and -rRef=1 to collect all references and then to do the real processing when the reference file is up to date. -x Just create the reference file. This can be used to refresh the reference file, it isn't always needed to have accurate references and by using this option groff will only be run once. AUTHOR
Jorgen Hagg, Lund, Sweden <jh@axis.se>. FILES
/usr/share/groff/1.19.2/tmac/tmac.m /usr/share/groff/1.19.2/tmac/mm/*.cov /usr/share/groff/1.19.2/tmac/mm/*.MT /usr/share/groff/1.19.2/tmac/mm/locale SEE ALSO
groff_mm(7), groff_mmse(7), groff(1), troff(1), tbl(1), pic(1), eqn(1) Groff Version 1.19.2 25 September 2015 MMROFF(1)
All times are GMT -4. The time now is 02:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy