![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
output - tab formatted - awk
Dear All, Good Day. I would like to hear your suggestions for the following problem: I have a file with 5 columns with some numbers in 16 lines as shown below. Input file: Code:
Col 1 Col 2 Col 3 Col 4 Col 5 12 220 2 121 20 234 30 22 9 156 25 129 320 94 7 . . . . I need to do the following Code:
Col_1new= Col1 ~ Col2 (# difference between Col1 and Col2) Col_2new= Col2 ~ Col3 Col_3new= Col3 ~ Col4 and so on. I need the output will be like this Code:
Col_1new Col_2new Col_3new Col_4new
208 218 119 101
and so on. The output should be in the column format. I am looking for an awk program to do the same. If anyone help me in this regard. Thanks in advance. Warm regards Fredrick. Last edited by radoulov; 11-27-2009 at 07:59 AM.. Reason: Use code tags, please! |
|
|||
|
Code:
awk 'BEGIN{print "Col_1new Col_2new Col_3new Col_4new"}
NR>1 {print $2-$1,$3-$2,$4-$3,$5-$4}' urfile
or Code:
awk 'BEGIN{print "Col_1new Col_2new Col_3new Col_4new"}
NR>1 {printf "%s\t%s\t%s\t%s\n", $2-$1,$3-$2,$4-$3,$5-$4}' urfile |sed 's/-//g'
|
| Bits Awarded / Charged to radoulov for this Post | |||
| Date | User | Comment | Amount |
| 11-27-2009 | danmero | x < 0 ? -x : x | 1,000 |
|
|||
|
Code:
awk 'NR > 1 { for(i = 0; ++i < NF;){x = ($i - $(i+1)) ; x = x < 0 ? -x : x ; r = r ? r "\t" x : x} print r ; r = ""}' infile
|
| Sponsored Links | ||
|
|
| Bits Awarded / Charged to danmero for this Post | |||
| Date | User | Comment | Amount |
| 11-27-2009 | radoulov | i = 0; ++i < NF; | 1,000 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cut - columns with formatted Output | dhanamurthy | Shell Programming and Scripting | 9 | 05-19-2008 11:20 AM |
| Formatted Output | dhanamurthy | Shell Programming and Scripting | 6 | 05-13-2008 03:30 AM |
| Formatted output - awk | dhanamurthy | Shell Programming and Scripting | 3 | 05-12-2008 12:25 AM |
| formatted output with commas | joeyg | Shell Programming and Scripting | 4 | 03-04-2008 03:54 PM |
| Formatted output in KSH | psynaps3 | Shell Programming and Scripting | 1 | 07-05-2006 09:03 AM |