Sponsored Content
Top Forums Shell Programming and Scripting Comparing alternate lines of code Post 303025797 by Peasant on Monday 12th of November 2018 11:36:50 AM
Old 11-12-2018
Here is my effort to translate using input Smilie
Lines of input are enumerated to for easier grasp and are not in actual file / input the program is processing.
Code:
#
# Condition construct is met on line 1
# LAST2 is empty, LAST1 is defined as current processing line, or $0
#

1 a

#
# Condition construct is met on line 2
# LAST2 is defined as LAST1 (previous line), LAST1 as current processing line, or $0
# We do that till line 6, since condition is met, replacing the values of LAST1 / LAST2 accordingly.
#

2 b
3 c
4 d
5 e
6 f

#
# In this moment, on line 7, value of LAST1 is "f", while LAST2 is "e".
# Condition construct is not met for lines 7 to 10.
# LAST1/LAST2 do not change, nor those lines will be in output
#

7 e
8 f
9 e
10 f

#
# On line 11 LAST1 or LAST2 condition construct is met again.
# LAST2 is declared as "f", and LAST1 as "a" or $0 or current processing line
# The program continues to operate as above.
#

11 a
12 b
13 c
14 d
15 e
16 f

Hopefully that is correct.
Regards
Peasant.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

alternate lines from two files

A basic request two files want to combine them but on alternate lines (1 Reply)
Discussion started by: SummitElse
1 Replies

2. Shell Programming and Scripting

alternate lines

Hi, I'm new to Unix. I want to read the all the lines from a text file and write the alternate lines into another file. Please give me a shell script solution. file1 ----- one two three four five six seven newfile(it should contain the alternate lines from the file1) ------- one... (6 Replies)
Discussion started by: pstanand
6 Replies

3. Shell Programming and Scripting

comparing lines in file

i have 2 files and i want to compare i currently cat the files and awk print $1, $2 and doing if file1=file2 then fail, else exit 0 what i want to do is compare values, with column 1 being a reference i want to compare line by line and then still be able to do if then statement to see if worked... (1 Reply)
Discussion started by: sigh2010
1 Replies

4. Shell Programming and Scripting

reading alternate lines of a file

hi, i have 2 files. file1: 1 2 3 4 5 6 file2: a b c d e f g h i (5 Replies)
Discussion started by: vidyaj
5 Replies

5. Shell Programming and Scripting

Insert string in alternate lines

Hi All, In continuation of my previous thread 'Add text at the end of line conditionally', I need to further modfiy the file after adding text at the end of the line. Now, I need to add a fixed charater string at alternate lines starting from first line using awk or sed.My file is now as below:... (10 Replies)
Discussion started by: angshuman
10 Replies

6. Shell Programming and Scripting

Comparing lines of two different files

Hello, Please help me with this problem if you have a solution. I have two files: <file1> : In each line, first word is an Id and then other words that belong to this Id piMN-1 abc pqr xyz py12 niLM y12 FY4 pqs fiRLym F12 kite red <file2> : same as file1, but can have extra lds... (3 Replies)
Discussion started by: mira
3 Replies

7. Programming

Perl : joining alternate lines

Hi, I need to join every alternate line in a file for eg:input file $ cat abc abc def ghi jkloutput abc def ghi jklcode i wrote for this $ cat add_line.pl #!/usr/bin/perl -w my $count=1; #my $line=undef; my @mem_line; my $i=0; my $x=0; (2 Replies)
Discussion started by: sam05121988
2 Replies

8. UNIX for Dummies Questions & Answers

Comparing lines of data

Total UNIX Rookie, but I'm learning. I have columns of integer data separated by spaces, and I'm using a Mac terminal. What I want to do: 1. Compare "line 1 column 2" (x) to "line 2 column 2" (y); is y-x>=100? 2. If yes, display difference and y's line number 3. If no, increment x and y by... (9 Replies)
Discussion started by: markymarkg123
9 Replies

9. Shell Programming and Scripting

Grep values on alternate lines

Hi, I have a file like 2011|ACC|.* 2013|ACC|.* 2011|ACCC|.* 2013|ACCC|.* 2013|ACCV|.* 2011|ADB|.* 2013|ADB|.* 2011|ADBC|.* 2013|ADBC|.* 2011|AIA|.* 2013|AXJ|.* 2013|NNN|.* .* represnts any alphanumeric characters after this part of the string I need a code to return only the... (3 Replies)
Discussion started by: sam05121988
3 Replies

10. Shell Programming and Scripting

Process alternate lines in awk/sed/perl

hi.. i have a fasta file with the following format >sequence1 CCGGTTTTCGATTTGGTTTGACT >sequence2 AAAGTGCCGCCAGGTTTTGAGTGT >sequence3 AGTGCCGCAGAGTTTGTAGTGT Now, i want to read alternate line and add "GGGGGGGGGGG" to end of every sequence Desired output: >sequence1... (4 Replies)
Discussion started by: empyrean
4 Replies
Gtk2::SourceView2::Style(3pm)				User Contributed Perl Documentation			     Gtk2::SourceView2::Style(3pm)

NAME
Gtk2::SourceView2::Style HIERARCHY
Glib::Object +----Gtk2::SourceView2::Style METHODS
style = $style->copy PROPERTIES
'background' (string : default undef : readable / writable / construct-only) Background color 'background-set' (boolean : default false : readable / writable / construct-only) Whether background color is set 'bold' (boolean : default false : readable / writable / construct-only) Bold 'bold-set' (boolean : default false : readable / writable / construct-only) Whether bold attribute is set 'foreground' (string : default undef : readable / writable / construct-only) Foreground color 'foreground-set' (boolean : default false : readable / writable / construct-only) Whether foreground color is set 'italic' (boolean : default false : readable / writable / construct-only) Italic 'italic-set' (boolean : default false : readable / writable / construct-only) Whether italic attribute is set 'line-background' (string : default undef : readable / writable / construct-only) Line background color 'line-background-set' (boolean : default false : readable / writable / construct-only) Whether line background color is set 'strikethrough' (boolean : default false : readable / writable / construct-only) Strikethrough 'strikethrough-set' (boolean : default false : readable / writable / construct-only) Whether strikethrough attribute is set 'underline' (boolean : default false : readable / writable / construct-only) Underline 'underline-set' (boolean : default false : readable / writable / construct-only) Whether underline attribute is set SEE ALSO
Gtk2::SourceView2, Glib::Object COPYRIGHT
Copyright (C) 2009 by Emmanuel Rodriguez perl v5.14.2 2011-11-16 Gtk2::SourceView2::Style(3pm)
All times are GMT -4. The time now is 02:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy