Change 3 lines in one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change 3 lines in one line
# 1  
Old 03-16-2009
Bug Change 3 lines in one line

Hello,
I am trying to check for an specific string in the first line and if this one is ok, I will go down one line and check for another string if this is ok, I will go dowm again and create one line with the string, if it's not ok I discard it. This is what I try so far but it's not working.

Here is the original file, here if 142.117.130.00 exist and is SUCCESS( from line down), I will print
142.117.130.00 -> SUCCESS -> MDL/VOICECOM_INFO20090312141603.TXT
But is not working, below is the script I am using

TG_20090312_141536.log 142.117.130.00
TG_20090312_141536.log 03/12/2009 SUCCESS
TG_20090312_141536.log MDL/VOICECOM_INFO20090312141603.TXT
TG_20090312_143041.log 142.117.130.01
TG_20090312_143041.log 03/12/2009 FAILURE
TG_20090312_140048.log 142.117.130.01
TG_20090312_140048.log 03/12/2009 FAILURE
TG_20090312_183436.log 142.117.130.01
TG_20090312_183436.log 03/12/2009 SUCCESS
TG_20090312_183436.log /CED/SCED_FCED_ID1_T20090312183450.DAT
TG_20090312_183329.log 142.117.130.01
TG_20090312_183329.log 03/12/2009 SUCCESS
TG_20090312_183329.log /CGV/SCGV_FCGD_ID1_T20090312183342.VM.DAT
TG_20090312_183226.log 142.117.130.02
TG_20090312_183226.log 03/12/2009 SUCCESS
TG_20090312_183226.log /CGV/SCGV_FCGD_ID1_T20090312183239.YT.DAT

awk '{
if ($2 = 142.117.135.36)
a=$2
getline
if ($3 = SUCCESS)
s=$3
getline
print p" -> "s" -> "$2}' File.txt

I also tried the following

awk '/142.117.135.36/{
a=$2
getline
if ($3 = SUCCESS)
s=$3
getline
print p" -> "s" -> "$2}'

Please help me with this one
Thanks

Jose Jaimes
# 2  
Old 03-16-2009
Code:
awk '$2 ~ /142.117.130.00/ {a=$2; getline; if ( $3 ~ /SUCCESS/ ) {b=$3; getline; print a" -> " b " -> "$2}}' infile
142.117.130.00 -> SUCCESS -> MDL/VOICECOM_INFO20090312141603.TXT

# 3  
Old 03-16-2009
Many thanks,

looks like is working now, always the details make the difference
# 4  
Old 03-17-2009
hi, base on your input, below code will generate output, hope can help you some:

Code:
142.117.130.00--->SUCCESS---->MDL/VOICECOM_INFO20090312141603.TXT
142.117.130.01--->SUCCESS---->/CED/SCED_FCED_ID1_T20090312183450.DAT
142.117.130.01--->SUCCESS---->/CGV/SCGV_FCGD_ID1_T20090312183342.VM.DAT
142.117.130.02--->SUCCESS---->/CGV/SCGV_FCGD_ID1_T20090312183239.YT.DAT

code:
Code:
use strict;
my ($t1,$flag);
open my $fh,"<","a.txt";
while(<$fh>){
	chomp;
	if(/((?:\d{3}\.){3}\d{2})/){
		$t1=$1;
	}
	if(/SUCCESS/){
		$flag=1;
		next;
	}
	if($flag==1){
		my @tmp=split;
		print $t1,"--->SUCCESS---->",$tmp[1],"\n";
		$flag=0;
	}
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reading a file line by line and print required lines based on pattern

Hi All, i want to write a shell script read below file line by line and want to exclude the lines which contains empty value for MOUNTPOINT field. i am using centos 7 Operating system. want to read below file. # cat /tmp/d5 NAME="/dev/sda" TYPE="disk" SIZE="60G" OWNER="root"... (4 Replies)
Discussion started by: balu1234
4 Replies

2. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

3. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

5. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

6. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

7. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

8. UNIX for Dummies Questions & Answers

append following lines to 1st line, every 3 lines

I have output like this: USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 USER_ID 12/31/69 19:00:00 12/31/69 19:00:00 ... where USER_ID is a unique user login followed by their login timestamp and... (6 Replies)
Discussion started by: MaindotC
6 Replies

9. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

10. Shell Programming and Scripting

Script to change file contents line by line

Hi, I'm struggling to write a script to do the following, -will go through each line in the file -in a specific character positions, changes the value to a new value -These character positions are fixed througout the file ----------------------- e.g.: file1.sh will have the following 3... (4 Replies)
Discussion started by: vini99
4 Replies
Login or Register to Ask a Question