Logic needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logic needed
# 1  
Old 05-29-2012
Logic needed

input :
Code:
employee_id, salary
-------------------
10,          1000
20,          2000
30,          3000
40,          5000


output:
Code:
employee_id, salary, next_row_salary
------------------------------------
10,          1000,       2000
20,          2000,       3000
30,          3000,       5000
40,          5000,       Null

Please gimme the command to get this output

Last edited by Franklin52; 05-29-2012 at 07:09 AM.. Reason: Please use code tags
# 2  
Old 05-29-2012
Hi


Code:
$ awk '{ if(x){print x", "$2;}x=$0;}END{print x",           NULL"}' FS="," file
10,          1000,           2000
20,          2000,           3000
30,          3000,           5000
40,          5000,           NULL


Guru.

Last edited by guruprasadpr; 05-29-2012 at 07:42 AM.. Reason: added comma for last line
# 3  
Old 05-29-2012
Thanks Guru..It worked..Could you please explain that if statement
# 4  
Old 05-29-2012
Hi
The idea is to print the last line along with the second column of the current line. To get the last line, we store the current line in x which in turn becomes the last line in the next iteration.

Guru.
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logic needed to recursive looping in the script

Hello i have a requirement where in a file i will get string. The length could be from 1 to 20. if the string is less than 6 characters ( ex: ABCD) . i need to append 'X' on right hand side to make it 6 characters (ex: ABCDXX). if suppose i get the same string from the file as ABCDXX then i... (5 Replies)
Discussion started by: dsdev_123
5 Replies

2. UNIX for Dummies Questions & Answers

logic needed to extract lines

Hi All, Are there any logic to extract the only lines between first two *TM* (which is marked in blue)? VOL1HST99 0 HDR1A999999S 999999HST99 HDR2F001200012001 UHL1 0729609000001 000000 *TM*^^^^^^^^^^^^^^^^^^^^^^ 01012610252171017301805000... (2 Replies)
Discussion started by: ganapati
2 Replies
Login or Register to Ask a Question