Hi I have to file in with 1 similar colomn.
from both files i want similar values from column1 and col2 from file1 and col2 from file2 in file 3
file1
[CODE]colomn 1 colomn2
rmoved
[CODE]
Hi I have to file in with 1 similar colomn.
from both files i want similar values from column1 and col2 from file1 and col2 from file2 in file 3
file1
[CODE]colomn 1 colomn2
rmoved
[CODE]
try
join file1 file2
awk 'NR==FNR{A[$1]=$0;next}{if(A[$1]){print A[$1],$2}}' file1 file2
Its not working...
What not working....?
Please look......
$ cat file1
8017172R 106126673.58
8017167R 139247928.99
2017917R 176606549.79
3514668R 277370594.03
2068764R 295968115.42
2515401R 420124600.33
7014281R 476346209.48
3012011R 526133734.06
2066522R 571615410.68
$ cat file2
8017172R 1061266735N
2015035R 1091944446N
8017167R 1392479289N
2017917R 1766065498N
6030741R 2052725599N
3514668R 2773705940N
2068764R 2959681154N
6030731R 3047202440N
2515401R 4201246003N
1006497R 4409300829N
6030777R 4435105434N
7014281R 4763462094N
$ awk 'NR==FNR{A[$1]=$0;next}{if(A[$1]){print A[$1],$2}}' file1 file2
8017172R 106126673.58 1061266735N
8017167R 139247928.99 1392479289N
2017917R 176606549.79 1766065498N
3514668R 277370594.03 2773705940N
2068764R 295968115.42 2959681154N
2515401R 420124600.33 4201246003N
7014281R 476346209.48 4763462094N
please check this
tell me please where I am wrong
It should work.
don't know whats going on...:rolleyes:
Have you tried using join
? Just remember files should be in sorted in order for using join.
i m using kshell..should it be a problem?
---------- Post updated at 07:37 PM ---------- Previous update was at 07:35 PM ----------
Yes it is sorted using join i am getting only 1 row as out put
pin@ssdb0220[mir]$ join file11 file12
1061266735N 126673.58
---------- Post updated at 08:14 PM ---------- Previous update was at 07:37 PM ----------
some one please help me to get it in some different form
Try this:
sort file10 > f1
sort file11 > f2
join f1 f2
Getting output :
2017917R 176606549.79 1766065498N
2068764R 295968115.42 2959681154N
2515401R 420124600.33 4201246003N
3514668R 277370594.03 2773705940N
7014281R 476346209.48 4763462094N
8017167R 139247928.99 1392479289N
8017172R 106126673.58 1061266735N
Thank It did work
---------- Post updated at 02:12 PM ---------- Previous update was at 02:01 PM ----------
One more help
while loop is executing but I am not getting complete data in file
what I am getting is a single row instead of 9
#! bin/ksh
cat file12 | awk '{print $1}' >> FNN.txt
while read line
do
a=`grep $line file12 | awk '{print $3}' | cut -c 1-8`
b=`grep $line file12 | awk '{print $3}' | cut -c 9-10`
c=`echo "$a.$b"`
d=`grep $line file12 | awk '{print $2}'`
e=`echo $d - $c|bc`
echo "FNN,Actual Charges,Sent Charges,Remaining Charges" > check.txt
echo "$line,$d,$c,$e" >> check.txt
done<FNN.txt
output
pin@ssdb0220[mir]$ cat check.txt
FNN,Actual Charges,Sent Charges,Remaining Charges
8017172R,106126673.58,10612667.35,95514006.23
In FNN.txt I have below data
File12 has below data
expected output
.
.
.
.
.9 FNN mentioned in fNN.txt
---------- Post updated at 02:30 PM ---------- Previous update was at 02:12 PM ----------
find out result
echo statement to be mentioned outside the loop
echo "FNN,Actual Charges,Sent Charges,Remaining Charges" > check.txt
cat file12 | awk '{print $1}' >> FNN.txt
while read line
do
a=`grep $line file12 | awk '{print $3}' | cut -c 1-8`
b=`grep $line file12 | awk '{print $3}' | cut -c 9-10`
c=`echo "$a.$b"`
d=`grep $line file12 | awk '{print $2}'`
e=`echo $d - $c|bc`
echo "$line,$d,$c,$e" >> check.txt
done<FNN.txt
---------- Post updated at 08:57 PM ---------- Previous update was at 02:30 PM ----------
Thanks lot for your help every one