I'd like to divide the values of the second column by its last entry (here 9.82197e-08).
I would be thankful if someone could show me how to do it in Linux.
Thanks!
Last edited by RudiC; 03-31-2016 at 07:41 AM..
Reason: Added code tags
"Do it in Linux" is somewhat ambiguous. Do you want to deploy a shell script, an awk (or other tool) script? Any attempts/thoughts/ideas from your side?
Sorry, I should have been more clear.
I searched in the forum and I saw a similar post as mine by for dividing a column by its first number using awk. here is what was suggested:
Now, I'm wondering how I can do the same but by dividing the column by its last number.
There are several possible approaches. For small files like above, you can keep all input in memory, try
This may work on some but not all awk versions depending on the NR and $2 values being retained in the END section or not.
For larger files, you might want to extract the last line with e.g. tail, or reverse the overall line order with tac, or run through the file twice.
NR
The ordinal number of the current record from the start of input. Inside a BEGIN action the value shall be zero. Inside an END action the value shall be the number of the last record processed.
So one should be able to use NR and instead of $2, you could use T2[NR]
Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records
Table
---------
Col1 col2 col3 col4 ....................col20
1 2 3 4 .................... 20
a b c d .................... v
... (11 Replies)
please write a shell script
Table
--------------------------
1 2 3 a b c
3 4 5 c d e
7 8 9 f g h
Output should be like this
---------------
1 2 3
3 4 5
7 8 9
a b c
c d e
f g h (1 Reply)
I currently have two programs written in C named "remove" and "calculate.
When I call ./remove it removes some data from stdin.
When I call ./calculate which takes in an argument and also data from stdin and calculates and returns a value.
Currently writing a script that calls both of these... (1 Reply)
Input file :
5 20
500 2
20 41
41 0
23 1
Desired output :
5
2
20
0
1
By comparing column 1 and 2 in each line, I hope can print out the column with smallest number.
I did try the following code, but it don't look good :( (2 Replies)
Hi Guys,
I have a question on how i can get the column number in a file and used it in awk.
i have a file which it has these records inside it.
... (7 Replies)
Does anyone know how to include as a script maybe an "echo" warning that explains that if a user uses the second number "zero" when dividing, that the result will BE "zero."
I need, example: 5/0 (second number) = 0, in script form.
current script:
echo "Enter a number"
read num1
echo... (4 Replies)
Hi!
Is there an easy way (maybe using awk??) to divide the values of one column of the file by it's first entry..
If I have a column:
3
4
5
6
7
I would like to divide it by 3.
I want to do this for more than 100 files, so it wouldn't be practical to open file by file and... (26 Replies)
I have a data file that is arranged like this:
Marketing Ranjit Singh Eagles Dean Johnson FULL
Marketing Ken Whillans Eagles Karen Thompson FULL
Sales Peter RobertsonGolden TigersRich Gardener PART
President Sandeep Jain Wimps Ken Whillans CONT... (7 Replies)
Hi all,
i was doing a small program where if i was to be given the first 3 letters of any month i.e. in the form of Jan or Apr then it would return the column number where it finds a match. To do this i created a 12 element array of months with first 3 letters and if i echo'ed the contents of... (2 Replies)