|
Blue Forest http://www.lslnet.com at 11:18 on June 26, 2006
Asked an array of value-awk problem.
A document
-->
No. 2 is intended to replace the field according to the index. Or
A department-> 0
1-> departments B
2> C sector
First compiled the following script :
-->
Can get correct results.
The question now is are many indexes, turn into k[? D4 "department?" The method is relatively more complicated.
There is no simple solution to the array k assignment?
C language can be written as follows :
K[]={ "Sector A", "Sector B" and "C sector", "Sector D")
Awk are not so lazy? |
Asked an array of value-awk problem.
If indexes are many, the proposal to build a paper b table as a replacement. B use awk score from the corresponding value of a replacement for the replacement. |
Asked an array of value-awk problem.
| Asked an array of value-awk problem.
-->
Then use the shell arrays do not know whether this is feasible? : Oops :
Set K "department of A" and "B sector", "departments C" and "D department"
Echo ${K[n]} |
Asked an array of value-awk problem.
Albanians have another lazy
K[]={ "Sector A", "Sector B" and "C sector", "Sector D")
Try this, a document which even [b][i]k[]={ "[/i][/b] are omitted, the importation of many smaller letters ^_^
R2007 $ [code]r2007@www a cat
DeptA
DeptB
DeptC
DeptD
R2007@www r2007 $ cat b
Aaa 0
Bbb 1
Ccc 2
Ddd 0
Eee 2
Fff 2
R2007@www r2007 $ awk '{if (NR==FNR) k[i++]=$0;else print $ 1, k[$2]}' ab
Aaa deptA
Bbb deptB
Ccc deptC
Ddd deptA
Eee deptC
Fff deptC
R2007@www r2007 $ [/code] |
Asked an array of value-awk problem.
It seems handy way or ksh
Bjgirl recommend to the school ksh information bar
//bow
| Asked an array of value-awk problem.
| Asked an array of value-awk problem.
To r2007 :
The reason that I did not use the document indexing, awk is not solving the problem of reading data from various documents.
Awk BEGIN{} open up the possibility of handling their own indexing documents ah?
For example,
BEGIN{
K1=`cat indexfile1`;
K2=`cat indexfile1`;
) (This is only the ideas, not the implementation) |
Asked an array of value-awk problem.
R2007 not have the time to solve the problem of indexing documents?
Digest digest bars.
Of course, there are other ways of reading. |
Asked an array of value-awk problem.
-->
If (NR==FNR) can only solve the problem of reading data from a document indexing! |
Asked an array of value-awk problem.
Can be used to resolve even join? ? |
Asked an array of value-awk problem.
-->
Usually only one document indexing, if the merger is the number may no longer be used in awk can be obtained through separate Document, document indexing method will be placed in front, followed by the need to handle paper. Cases
[code]r2007@www R2007 $ cat idx1
Mm meimei
Gg gege
Jj jiejie
R2007@www r2007 $ cat idx2
010 beijing
021 gov
022 tianjin
$ Cat tel r2007@www r2007
010 123456 mm
010 888888 139330
022 7777777 jj
021 5555555 mm
R2007@www r2007 $ awk '{if (FILENAME== "idx1") i1[$1]=$2;else if (FILENAME== "idx2") i2[$1]=$2;else print i2[$1], $ 2. i1[$3]} 'idx1 idx2 tel
Beijing EPI meimei
Beijing 888,888 gege
Tianjin 7777777 jiejie
Gov 5555555 meimei
R2007 $ r2007@www
[/code] |
Asked an array of value-awk problem.
Very grateful!
No wonder only close awk language, a language not open! It is not. |
Asked an array of value-awk problem.
, Learn-ing |
Asked an array of value-awk problem.
The awk language above question :
Awk '{if (NR==FNR) k[i++]=$0;else print $ 1, k[$2]}' ab
Which (NR==FNR), is it not all the documents are in line with these conditions? There behind the document was different from the results or output, is a sequence of notes. |
| |