How do I use paste command in while condition??

there are lot of files where in mostly all the file contains 2columns

Al,1
Ail,13
Al,3
Al,1
Al,3
Al,2
Al,3
Al,1
Al,1
Al,1

[/CODE]

My requirement is i wanted only the second column of every file as a column ony in the base file... I used paste command... but it is not helping as I'm using while condition.

while read dline
do
while read opline
do
grep $dline Combo_31Jan.csv|grep -i "$opline" |awk -F, '{print $1","$7}'>>combo_operncount.$dline.$opline
done < operator.txt
done < date.txt
while read dline
do
>blank.$dline
while read opline
do
#paste blank.$dline combo_operncount.$dline.$opline >> FC7DFILE.$opline

#mv FC7DFILE.$opline blank.$dline
done < operator.txt
done < date.txt

[/CODE]

operator.txt and date.txt contains

operator.txt

AEL
AL
TMO
VOE

date.txt

2013-01-28
2013-01-29
2013-01-30
2013-01-31

[/CODE]

It would be better if you could provide desired output and all the inputs.

Regards,

Pamu

input

head combo_operncount.2013-01-31.VOD

vone,12
vone,4
vone,1
vone,3
vone,3
vone,1
vone,1
vone,1
vone,1
vone,1

similar to this I have several files classified on basis of date..

head combo_operncount.2013-01-30.VOD

vone,3
vone,1
vone,1
vone,3
vone,1
vone,1
vone,1
vone,3
vone,3
vone,1

[/CODE]

My requirement is I want o/p to be in the below format

vone,12,3,.....,... it goes on , total from 2nd col to last
vone,4,1
vone,1,1
vone,3,3
vone,3,1
vone,1,1
vone,1,1
vone,1,3
vone,1,3
vone,1,1

the final o/p wil be with total and the and all othe columns

---------- Post updated at 12:58 PM ---------- Previous update was at 12:56 PM ----------

PS: there are some files which have lesser number of lines so i want that to be replaced to 0 and then i want the total...

Try sth like this..

awk -F, '{A[FNR]=A[FNR]?A[FNR] FS $NF?$NF:"0":$0;
        if(FNR>t){t=FNR}}
        END{for(i=1;i<=t;i++){print A}}' file1 file2

what are file1 & file2 ??

It aint working Pamu,I don't see column 1 as well....

---------- Post updated at 01:36 PM ---------- Previous update was at 01:23 PM ----------

input

ale,27
ale,1
ale,12
ale,5
ale,3
ale,3
ale,1
ale,1
ale,1

==> combo_operncount.2013-01-29.ALE <==
ale,65
ale,38
ale,2
ale,1
ale,7
ale,16
ale,1
ale,2
ale,2
ale,4

==> combo_operncount.2013-01-30.ALE <==
ale,45
ale,13
ale,1
ale,1
ale,1
ale,1
ale,9
ale,3
ale,2
ale,3

==> combo_operncount.2013-01-31.ALE <==
ale,41
ale,20
ale,1
ale,1
ale,9
ale,12
ale,1
ale,3
ale,2
ale,5

[/CODE]

required o/p

ale,57,65,45,41
ale,27	,38	,13	,20
ale,1	,2	,1	,1
ale,12	,1	,1	,1
ale,5	,7	,1	,9
ale,3	,16	,1	,12
ale,3	,1	,9	,1
ale,1	,2	,3	,3
ale,1	,2	,2	,2
ale,1	,4	,3	,5

[/CODE]

---------- Post updated at 01:39 PM ---------- Previous update was at 01:36 PM ----------

there are several files like this whic are classified based on the date....
these files are also generated from some script.

there are few files with different count of lines

for ex

A contains 100 lines
B contains 120 lines
C contains 130 lines

then every file shul hav 130 line and the 2nd column for A & B file which has lesser line shul hav 0 as value....

Your last requirement "undefined lines should have 0 value" applies for a matrix (two dimensional array).
Which GNU/Posix awk:

awk -F, '
FNR==1 { ++xm }
FNR>ym { ym=FNR }
{ a[FNR,xm]=$2 }
END {
for(y=1;y<=ym;y++) {
  for(x=1;x<=xm;x++) printf FS "%d",a[y,x]
  printf "\n"
 }
}' file1 file2 ... fileN
1 Like

hi how can i display the 1st column??? It aint displaying 1st column

You did not say much about the 1st column, are they all the same?
Therefore I left it as an exercise.
The following is a 3-dimensional array solution, that is maybe an overkill of your requirement. "Just because you have a hammer not every problem is a nail."

awk -F, '
FNR==1 { ++xm }
FNR>ym { ym=FNR }
{ a[$1,FNR,xm]=$2; b[$1]=1 }
END {
for(z in b) {
  for(y=1;y<=ym;y++) {
    printf "%s",z
    for(x=1;x<=xm;x++) printf ",%d",a[z,y,x]
    printf "\n"
  }
 }
}' file1 file2 ... fileN