Linux / UNIX Tech Support Forum
This is a discussion on Subtracting different numbers from different columns of a file by awk within the Shell scripting forums, part of the Development/Scripting category; Hi, I tried to subtract a specific number which I have already read from another file to whole numbers of ...
Register free or login to your account to remove all advertisements.
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
Thread Tools | Display Modes |
|
|||
|
Hi,
I tried to subtract a specific number which I have already read from another file to whole numbers of a column each time and then I want to have my whole file by these changes. I used below command but it did not work properly. I wonder how I could solve the problem?? I want that each time it could read a number from medium_magnitude_test.param file and then subtract the number from the given column and then it saves the results. for FILTER in MB416 MB461 MB485 MB518 MB571 MB604 MB646 MB696 MB753 MB815 MB856 MB914 do for i in $(seq 6 17); do k=`grep "MAGZP_${FILTER}" ${MainD}/medium_magnitude_test.param | awk '{print $3}'` echo ${k} awk 'BEGIN { $i=$i-k print $0 }' ${MD}/seventeen_filters_10.asc > test00.asc done done |
|
|||
|
Quote:
|
|
|||
|
awk does not process data in the BEGIN block, hence, printing wouldn't work there. This is where you handle operation before awk start processing the data in the main section.
Try changing the following: awk 'BEGIN { $i=$i-k print $0 }' ${MD}/seventeen_filters_10.asc > test00.asc to: awk -v d=$k -v c=$i 'BEGIN { deduct=d; column=c; } { $column = $column - deduct; print $0 }' ${MD}/seventeen_filters_10.asc > test00.asc See if this works. Thanks, - NNS |
![]() |
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep numbers from file. | eawedat | Shell scripting | 3 | 16th August 2008 08:23 AM |
| Create output in columns | rakeshrhn | Shell scripting | 5 | 7th December 2007 06:27 PM |
| help me in editing this columns | sureshbup | Shell scripting | 1 | 12th December 2006 02:29 PM |
| rearranging columns in a text file | sureshbup | Shell scripting | 2 | 6th December 2006 09:43 AM |
| Calculations across different lines & columns of a file | Guest | Shell scripting | 2 | 16th September 2005 04:18 AM |