Change value for POSIX


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Change value for POSIX
# 8  
Old 08-31-2017
Hi,

I am using Bash shell.

I have set of Ids stored in a file and I am copying them in batches in array.


Code:
# Store Distinct ContainerIds  in Array
distinct_array=`sed ':a;N;$!ba;s/\n/ /g' output/EmployeeId_distinct.txt`
declare -a arr=($distinct_array)
echo " Total Number of Distinct Ids Stored in Array ${#arr[@]}"
batchsize=200


This is how I am calling the mongo

Code:
for((i=0; i < ${#arr[@]}; i+=batchsize))
 do
   IFS=,
   part=( "${arr[@]:i:batchsize}" )
  
   sed -i  "2i permissibleCars = [  ${part[*]} ]"  query/employee_Id_count.js
   mongo localhost:27045/employee_db -u user_user -p password123 < query/employee_Id_count.js >> output/employee_Id_count.txt 
   cat query/employee_Id_count.js >> query/employee_Id_count_total.js
done


My sample employee id would be like "XYZ:16772767:586748411"

mployee_Id_count.js file :--

Code:
DBQuery.shellBatchSize = 224361901 ; 
permissibleCars = ["XYZ:16772767:58675748411" ..... more 200 ids ]
db.getCollection('employee_contracts_nrt').aggregate([
{$match:
      {         employeeClass : "ownload",
                    EmployeeId: {"$in": permissibleCars},
                                "methods.name": "image",
                "methods.status": "ACTIVE"

        } },
{"$group" : {_id:"$EmployeeId", count:{$sum:1}}}
],
{ allowDiskUse: true}
);

It works perfectly fine if I pass say 150 batchsize but if crosses 4096 bytes it starts failing.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 08-31-2017 at 05:07 AM.. Reason: Added CODE tags.
# 9  
Old 08-31-2017
I'm not sure I fully understand what you're doing, but with IDs in a file to be transferred - unaltered, as far as I can see - into a .js script (which, btw, seems to be growing in every loop?), why do you do this via shell variables, arrays, operations and not with simple text tools / operations?
# 10  
Old 08-31-2017
The file size is not a issue . Can you explain more about file tool. I am not much aware of it
# 11  
Old 08-31-2017
I wasn't talking about file size, but you seem to be adding (NOT replacing!)
Code:
permissibleCars = ["XYZ:16772767:58675748411" ..... more 200 ids ]

in every loop, making employee_Id_count.js look like
Code:
DBQuery.shellBatchSize = 224361901 ;
permissibleCars = ["XYZ:16772767:58675748411" ..... more 200 ids ]
.
.
.

in the first run,
Code:
DBQuery.shellBatchSize = 224361901 ;
permissibleCars = [ 200 other ids ]
permissibleCars = ["XYZ:16772767:58675748411" ..... more 200 ids ]
.
.
.

in the second etc.

*nix has a wealth of text tools to manipulate, extract, modify, adapt text files, to name a few of which : awk, sed, cut, sort, etc. (see e.g. the coreutils package).
If you post sample data like the EmployeeId_distinct.txt file and how it should fit into the employee_Id_count.js, people in these fora will likely come up with ptoposals on how to do it.
# 12  
Old 08-31-2017
No, If you see it is not append it is insert . So, everytime the new record gets replaced.

---------- Post updated at 03:18 PM ---------- Previous update was at 03:05 PM ----------

Hi,

I have uploaded the EmployeeId_distinct.txt file at below location :--

Dropbox - EmployeeId_distinct.txt


The employee_Id_count.js would be

Code:
DBQuery.shellBatchSize = 224361901 ; 
permissibleCars = This will get passed from array .
db.getCollection('employee_details').aggregate([
{$match:
      {         employeeClass : "ownload",
                    EmployeeId: {"$in": permissibleCars},
                                "methods.name": "image",
                "methods.status": "ACTIVE"

        } },
{"$group" : {_id:"$EmployeeId", count:{$sum:1}}}
],
{ allowDiskUse: true}
);

# 13  
Old 08-31-2017
Quote:
Originally Posted by Abhayman
No, If you see it is not append it is insert . So, everytime the new record gets replaced.
.
.
.
Sure?
Code:
sed -i '2i XXX' /tmp/file2.txt
cat /tmp/file2.txt
21 1209
XXX
XXX
XXX
22 1210

after applying the sed command thrice ...

And, giving approximate results like
Quote:
.
.
.
Code:
DBQuery.shellBatchSize = 224361901 ; 
permissibleCars = This will get passed from array .
db.getCollection('employee_details').aggregate([
.
.
.

will help only if you yourself know exactly how to make them fit exactly. Do you?

Last edited by RudiC; 08-31-2017 at 07:32 AM..
# 14  
Old 08-31-2017
Basically it is something like this

Code:
{ echo "DBQuery.shellBatchSize = $employee_count ; "; cat query/employee_cemployeidd_count_tmp.js; } > query/employee_Id_count.js
    sed -i  "3i permissibleCars = [  ${part[*]} ]"  query/mployee_Id_count.js.js

But I have just posted the final one which is having issue . Sorry for the confusion.

Issue is more related to final mongo execution.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

POSIX compliance...

Thanks to all you guys about posix compliance I have learnt an enormous amount over the last few days. I have written a program that is an Egg Timer with simple animation. I now realise how sophisticated 'bash' is compared to full posix compliance. The code below has passed all of the tests from... (11 Replies)
Discussion started by: wisecracker
11 Replies

2. Programming

POSIX Thread Help

I want to create a program that creates 2 child process, and each of them creates 2 threads, and each thread prints its thread id. I0ve allread done that the outuput isn't the outuput i want. When a run the following comand "$./a.out | sort -u | wc -l" I have the folowing output 2 $: It should... (3 Replies)
Discussion started by: pharaoh
3 Replies

3. UNIX for Advanced & Expert Users

System V or POSIX

Hi , I am using UNIX network programming Vol1 (by R Stevens) book to learn about IPC. I would be using HP-UX,Solaris and Linux at my work. I have sections for POSIX and for System V in that book. I am quite confused in indentifying those OSs as POSIX or SYstem V. Can anyone please... (1 Reply)
Discussion started by: kumaran_5555
1 Replies

4. UNIX for Advanced & Expert Users

Posix threads

Hi, consider the code below: #include <stdio.h> . . struct myStruct { char *message ; int id; }; . . . void *thread_function( void *ptr ); nt main() { pthread_t thread1, thread2 ,thread3 ; struct myStruct nico1; (2 Replies)
Discussion started by: Behnaz
2 Replies

5. Programming

Posix

HI, When i am configuring php in SUN Solaris. I am getting the below error. configure: error: Your system seems to lack POSIX threads. Do i need to install POSIX? If so can somebody let me know where can i download POSIX for Solaris 8? Thanks, (2 Replies)
Discussion started by: Krrishv
2 Replies

6. Programming

POSIX threads

Hello ! Let's supose I have a main function in C , and two POSIX threads. I give you an example down : int main() { int something; char else; void *FirstThread(); void *SecondThread(); .. <start those two pthreads ..> return 0;} void *FirstThread() { ... } void *SecondThread()... (2 Replies)
Discussion started by: !_30
2 Replies

7. UNIX for Dummies Questions & Answers

how to read POSIX?

how to read POSIX? poe six or not? (3 Replies)
Discussion started by: robin.zhu
3 Replies

8. Programming

Unix(posix)

Please,does anybody can give me any general info about unix(posix) ? (1 Reply)
Discussion started by: Haris Astreos
1 Replies

9. Programming

ANSI C vs POSIX

can somebody explain about the ANSI C vs POSIX. say i was using open and fopen, i know that open is POSIX, and fopen is ANSI C. i read that that POSIX is a system call and ANSI C is like a standard library function. wouldn't the fopen function has to call on open function anyway to open any kind... (2 Replies)
Discussion started by: bb00y
2 Replies

10. UNIX for Dummies Questions & Answers

Posix and linux

What is posix? What is the relation between Posix, Unix and linux? (1 Reply)
Discussion started by: darbarilal
1 Replies
Login or Register to Ask a Question