Sponsored Content
Top Forums Shell Programming and Scripting Copy Column Value Of Next Line Into Current Line Post 302983425 by angshuman on Tuesday 11th of October 2016 02:28:23 PM
Old 10-11-2016
Hello RudiC,

Sorry if my question is not clear. Let me rephrase as below:

Replace value of column 5 of a line with value of column 4 of previous line provided value of column 5 is zero and value of column 1 and column 3 of both lines match.

Replace value of column 5 of a line with value of column 4 of same line + constant if value of column 5 is zero and value of column 1 and column 3 of a line does not match with its previous line.

Thanks
Angshuman

---------- Post updated at 11:58 PM ---------- Previous update was at 10:54 PM ----------

I am also trying to explain with the example:

Code:
1757890237|54|55570025|1474153200|1476745200
1757890237|42|55570025|1468796400|0  
1757890237|32|55570025|1471474800|0
1757890237|56|55570026|1474153200|1476745200
1757890237|34|55570026|1468796400|0
1757890237|44|55570026|1471474800|0
1757890237|58|55570027|1474153200|1476745200
1757890237|36|55570027|1468796400|0
1757890237|46|55570027|1471474800|0
1762391149|30|55570025|1468710000|0
1762391149|38|55570025|1468796400|0
1762391149|32|55570026|1468710000|0
1762391149|40|55570026|1468796400|0
1762391149|34|55570027|1468710000|0
1762391149|42|55570027|1468796400|0

In above example,
  1. column 5 of line 1 is not zero. Hence no action
  2. column 5 of line 2 is zero, value of column 1 and column 3 of line 2 matches with column 1 and column 3 of line 1, replace column 5 with value of column 4 of line 1
  3. In line 10, value of column 1 and column 3 does not match with value of column 1 and column 3 of column 9, also value of column 5 in line 10 is 0, replace value of column 5 of line 10 with a constant value.

Thanks
Angsuman
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to search a line and copy it to another line

Hi I have a log file (say log.txt). I have to search for a line which has the string ( say ERROR) in the log file and copy 15 lines after this into another file (say error.txt). Can someone give me the code and this has to be in PERL Thanks in advance Ammu (3 Replies)
Discussion started by: ammu
3 Replies

2. 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

3. Shell Programming and Scripting

Read and copy xml line by line and preserve tab?

I'm trying to read an xml file and copy it line by line to another file and want to preserve the tabs. What i'm trying to do is if I get to a certain line in the xml, I'm going to check to see if the next line is specifically what I want. If it's not, then I want to insert a single line of text... (4 Replies)
Discussion started by: DeuceLee
4 Replies

4. Shell Programming and Scripting

Vi Editor - How to paste the line concatenated with current line

I generally use yy to copy a line and then p to paste the line at end of current line. But is there a way to paste the copied line in concatenation with the current line with out going to next line. (3 Replies)
Discussion started by: paragkalra
3 Replies

5. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

6. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

7. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

8. Shell Programming and Scripting

Find in the current line and next line.

Hi, I have lines that have pattern like this. 1) productFamilyGroupIndex < Local.ProductFamilyGroup.capacity)) and 2) if (local.getProductFamilyGroup().size() >= Local.ProductFamilyGroup. capacity) So, If I need to find the pattern grep '\(< \|>= \)Local.*capacity'... (4 Replies)
Discussion started by: srikanthradix
4 Replies

9. UNIX for Dummies Questions & Answers

Printing the next line side by to the current line

Help, I have a text file which looks like disco 5674536 3456 jambo disco 453678 4578 jambo I would like to have an output which looks like below disco 3456 disco 4578 (4 Replies)
Discussion started by: Indra2011
4 Replies

10. Shell Programming and Scripting

Append Next line with current Line bassed on condition

Hi, I have an XML file and I am tring to extract some data form it, after lot of data cleaning process, I ended up with an issue, and need your urgent support. my current input data in below format: <Node>xxxxxx <Node>yyyyy</Node> <Node>zzzzzz <Node>12345</node> I need... (9 Replies)
Discussion started by: rramkrishnas
9 Replies
COLRM(1)						    BSD General Commands Manual 						  COLRM(1)

NAME
colrm -- remove columns from a file SYNOPSIS
colrm [start [stop]] DESCRIPTION
The colrm utility removes selected columns from the lines of a file. A column is defined as a single character in a line. Input is read from the standard input. Output is written to the standard output. If only the start column is specified, columns numbered less than the start column will be written. If both start and stop columns are spec- ified, columns numbered less than the start column or greater than the stop column will be written. Column numbering starts with one, not zero. Tab characters increment the column count to the next multiple of eight. Backspace characters decrement the column count by one. ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of colrm as described in environ(7). EXIT STATUS
The colrm utility exits 0 on success, and >0 if an error occurs. SEE ALSO
awk(1), column(1), cut(1), paste(1) HISTORY
The colrm command appeared in 3.0BSD. BSD
August 4, 2004 BSD
All times are GMT -4. The time now is 08:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy