Search Results

Search: Posts Made By: arunkumar_mca
2,306
Posted By vgersh99
awk -F'[;]' '{ t[$1 OFS $2]+=$3 } END { for (i in...
awk -F'[;]' '{ t[$1 OFS $2]+=$3 } END { for (i in t) print i, t[i] }' myFile
For the 'Also' part... please post sample representative input.
2,306
Posted By Yoda
Your data appears to have variable number of...
Your data appears to have variable number of columns. The code you wrote will work if all rows in your input file has exactly three columns.

But if that is how your input data is, then one...
2,306
Posted By Scrutinizer
I tried the second one and it works, but your...
I tried the second one and it works, but your input file seems to broken. Try it with this one:
10264;ATE;12
10265;SES;11
10266;AUT;50
10264;ATE;10
10265;SES;13
10266;AUT;89
10264;ATE;1...
2,583
Posted By RudiC
Try join -t";" -a1 -a2 -eNA -oauto...
Try
join -t";" -a1 -a2 -eNA -oauto file[12]
2,523
Posted By RudiC
Try also awk ' {print substr($0,1,8)...
Try also
awk '
{print substr($0,1,8) substr (sprintf ("%d", substr($0, 9, 6) "000"), 1, 6) substr($0,15)
}
' file
2,523
Posted By RavinderSingh13
Hello arunkumar_mca, Could you please try...
Hello arunkumar_mca,

Could you please try following once.


awk '{val1=substr($0,9,6);val2=val1+0<10000?sprintf("%06d",val1*1000):val1;print substr($0,1,8) val2 substr($0,15)}' Input_file

...
1,946
Posted By RudiC
Why not use awk for the arithmetics as well?
Why not use awk for the arithmetics as well?
1,946
Posted By Scrutinizer
Hi, try: awk ' { ...
Hi, try:
awk '
{
result=substr($0,50,5) * substr($0,55,6) * substr($0,88,3) * substr($0,81,7) / 10^8
tot+=result
print result
}
END {
print tot
}
' file

In GNU...
1,710
Posted By Don Cragun
Note that the code RavinderSingh13 suggested in...
Note that the code RavinderSingh13 suggested in post #2 in this thread will change the 35th character on every line; not just on lines where the original character in that position was "8".

For...
1,040
Posted By stomp
cut cut -c1-35,42- data.txt sed sed...
cut

cut -c1-35,42- data.txt

sed
sed -re 's/(.{35}).{6}/\1/' data.txt

Perl

perl -pe 's/^(.{35}).{6}/$1/' data.txt

GNU(!) awk

awk 'match($0,/^(.{35}).{6}(.*)/,res){print res[1]...
1,089
Posted By nezabudka
grep -f <(sed 's/.*/^&/' file2) file1
grep -f <(sed 's/.*/^&/' file2) file1
1,089
Posted By Corona688
You're not comparing the same thing, try awk...
You're not comparing the same thing, try
awk 'NR==FNR{a[substr($0,1,8)];next} (substr($2,1,8) in a)' file2 file1
1,089
Posted By Corona688
You're giving it file_1 first, which isn't the...
You're giving it file_1 first, which isn't the file containing the keys to match with, and later, matching against column 1 of the other wrong file.

So, let's try saving the keys from file_2, then...
885
Posted By RavinderSingh13
Hello arunkumar_mca, Good that you have...
Hello arunkumar_mca,

Good that you have posted and informed us that you have found the solution. I would like to suggest you that in these cases you could do 2 things.

1st: Add "solved" TAG in...
885
Posted By MadeInGermany
bash and ksh can do process substitution: diff...
bash and ksh can do process substitution:
diff <(cut -f1 -d. file1) <(cut -f1 -d. file2)
Everything after a dot is cut off, before it's handed to diff.
Or more general, cut decimals from *all*...
2,198
Posted By Peasant
Is the above a mistake, since you posted...
Is the above a mistake, since you posted subtraction bigger then 5 or 6 and above is 16 ?

Well you really gave me a challenge for one who doesn't code like this on a daily basis :D
This is surely...
2,198
Posted By Peasant
All the subtraction done on fields ($2,$10)...
All the subtraction done on fields ($2,$10) depends on year on field $4, the variance defined.
If no input on $2 matches string PP<number>, $2 is printed as is, unchanged.
If no input on $10...
2,198
Posted By Peasant
Fixed some typos..
I'm not sure i follow.
Input now is also inconsistent, with first two rows having 13 fields and last having 12.

Now you say you require fields 2,4 and 10, but on expected output you changed only...
1,285
Posted By MadeInGermany
Put the global substitution first: sed 's/ *|...
Put the global substitution first:
sed 's/ *| */|/g; s/^|//; s/|$//'
1,285
Posted By RudiC
This works with my GNU sed 4.4: sed...
This works with my GNU sed 4.4:



sed -r 's/(^\|| |\|$)//g' file
3464114|10|REPORT|CA|1|0|4825400|0|213167|939396524
1,285
Posted By rdrtx1
sed 's/^ *[|] *//; s/ *[|] */|/g; s/ *[|] *$//'...
sed 's/^ *[|] *//; s/ *[|] */|/g; s/ *[|] *$//' file.out > format.out
950
Posted By vgersh99
In addition to double-quoting $1 in print_log,...
In addition to double-quoting $1 in print_log, I'd enable set -x in the script and in the function call and see what comes out....
950
Posted By vgersh99
Actually it's the same problem with echo as you...
Actually it's the same problem with echo as you had with execute.
Double-quote the argument to the command.
743
Posted By Scrutinizer
For sort to work you also have to specify the...
For sort to work you also have to specify the field separator. You can try:
sort -ut\; -k1,1 fileHowever, this is not standard (POSIX) behavior for sort and cannot be relied upon and some sorts will...
743
Posted By RudiC
In order to retain the special structure of the...
In order to retain the special structure of the fourth line's $12, try
awk -F\; '$12 == $12+0 {$12 = sprintf ("%03d", $12)} 1' OFS=";" file...
Showing results 1 to 25 of 104

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