Search Results

Search: Posts Made By: Lakme Pemmaiah
7,505
Posted By MadeInGermany
Thanks for the finding. Then, for esthetic...
Thanks for the finding.
Then, for esthetic reasons, I prefer
awk '(FNR==1) {x=int(NR/2)} (FNR==x) {print; exit}' infile infile
7,505
Posted By Don Cragun
Unfortunately, if infile contains an odd number...
Unfortunately, if infile contains an odd number of lines (3 for example), none of these will work.
In the 1st awk script int(3/2) is 1, not 2; so that script prints the 1st line instead of the 2nd...
7,505
Posted By MadeInGermany
The b variable, incrementing on every line, is...
The b variable, incrementing on every line, is identical with awk's NR variable.
So one can shorten it to
awk '{a[NR]=$0;} END {print a[int(NR/2)]}' infilea is an array that stores each line.
So...
7,505
Posted By in2nix4life
awk '{a[b++]=$0;}END{print a[int(b/2)];}' infile
awk '{a[b++]=$0;}END{print a[int(b/2)];}' infile
146,925
Posted By Neo
Rules for Homework & Coursework Questions Forum
Homework Help:

On Posting Questions:

Any and all high school and undergraduate homework assignments or textbook style exercises for which you are seeking assistance are to be posted only in...
Showing results 1 to 5 of 5

 
All times are GMT -4. The time now is 03:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy