Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get values from a table 1

Status
Not open for further replies.

rossyeperez

Technical User
Feb 1, 2007
15
MX
I have the following table

1 2 3 4 5 7
2 3 4 5 6 7
3 3 2 1 5 4
4 5 6 7 8 9

I would like to get the following result

start = 1 --> "top value in the first column"
stop = 4 --> "bottom value in the first column"
count = 6 --> " count number of column in the table"
and after get these values print the table below the values:

start = 1
stop = 4
count = 6
1 2 3 4 5 7
2 3 4 5 6 7
3 3 2 1 5 4
4 5 6 7 8 9




 
Hi

Code:
[gray]# for small files[/gray]
awk 'NR==1{print"start = "$1;c=NF}{s=$1;l[NR]=$0}END{print"stop = "s;print"count = "c;for(i=1;i in l;i++)print l[i]}' /input/file

[gray]# for big files[/gray]
awk 'FNR==1&&NR!=1{print"start = "$1"\nstop = "s"\ncount = "NF}{s=$1}FNR!=NR' /input/file /input/file

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top