Solution for Argument list too long The Next CEO of Stack Overflowfind + xargs: argument line too longSolving “mv: Argument list too long”?xargs line too longbash: /usr/bin/perl: Argument list too long/usr/bin/awk: Argument list too longArgument list too long with just 5000 files/bin/cat: Argument list too longxargs: argument line too longArgument list is too long for /bin/awsbash: assign variable and print to stdout in same command

How to avoid supervisors with prejudiced views?

Won the lottery - how do I keep the money?

Proper way to express "He disappeared them"

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

What does "Its cash flow is deeply negative" mean?

Writing differences on a blackboard

"misplaced omit" error when >centering columns

Why isn't the Mueller report being released completely and unredacted?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

RigExpert AA-35 - Interpreting The Information

How to get from Geneva Airport to Metabief, Doubs, France by public transport?

Is it convenient to ask the journal's editor for two additional days to complete a review?

Does soap repel water?

Can I use the load factor to estimate the lift?

Is it professional to write unrelated content in an almost-empty email?

How is this set of matrices closed under multiplication?

Can this equation be simplified further?

Why, when going from special to general relativity, do we just replace partial derivatives with covariant derivatives?

Domestic-to-international connection at Orlando (MCO)

What steps are necessary to read a Modern SSD in Medieval Europe?

Why is information "lost" when it got into a black hole?

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

Yu-Gi-Oh cards in Python 3



Solution for Argument list too long



The Next CEO of Stack Overflowfind + xargs: argument line too longSolving “mv: Argument list too long”?xargs line too longbash: /usr/bin/perl: Argument list too long/usr/bin/awk: Argument list too longArgument list too long with just 5000 files/bin/cat: Argument list too longxargs: argument line too longArgument list is too long for /bin/awsbash: assign variable and print to stdout in same command










0















I have the below shell script which reads a file, copies the content of the file to a variable and passes the variable as argument to another command.



declare -a arr=()
while IFS= read -r var
do
arr+=( $var )
done < "accounts.json"
args=''
for j in "$arr[@]"
do
args="$args $j"
done
peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced",'""$args""']'



This works very well when the accounts.json file is small. But I get an error that says "Argument list too long" when the size of accounts.json is too large. I have tried xargs but to no success.



edit 1:



below is example json file with only two rows



["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]


Below is what a peer command would look like with actual data



peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced","["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]"]'









share|improve this question









New contributor




user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    You would not be able to use xargs here as you (I assume) you need to give the complete JSON document in one go. Is that correct? Can that peer command be made to read the document from a file instead from the command line? (Note: I'm unsure what peer is).

    – Kusalananda
    2 days ago











  • Yes, I need the complete json document in one go. I cannot use the peer command to read document from a file. peer is not a native unix/linux command. It comes from Hyperledger fabric (a blockchain service).

    – user344247
    2 days ago







  • 1





    Please show a sample of the input file and show what the -c argument is supposed to look like. I bet a simple jq script is all that's required. That would mean you don't need to break up the file into lines and then combine the lines into a string: jq would do that for you.

    – glenn jackman
    2 days ago











  • @glennjackman That wouldn't make the actual argument to peer shorter in the end, would it?

    – Kusalananda
    2 days ago











  • @glennjackman. I have edited my question and added a few examples. Please don't worry about use of double quotes inside single quotes. I have made sure to have escape characters

    – user344247
    2 days ago
















0















I have the below shell script which reads a file, copies the content of the file to a variable and passes the variable as argument to another command.



declare -a arr=()
while IFS= read -r var
do
arr+=( $var )
done < "accounts.json"
args=''
for j in "$arr[@]"
do
args="$args $j"
done
peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced",'""$args""']'



This works very well when the accounts.json file is small. But I get an error that says "Argument list too long" when the size of accounts.json is too large. I have tried xargs but to no success.



edit 1:



below is example json file with only two rows



["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]


Below is what a peer command would look like with actual data



peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced","["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]"]'









share|improve this question









New contributor




user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1





    You would not be able to use xargs here as you (I assume) you need to give the complete JSON document in one go. Is that correct? Can that peer command be made to read the document from a file instead from the command line? (Note: I'm unsure what peer is).

    – Kusalananda
    2 days ago











  • Yes, I need the complete json document in one go. I cannot use the peer command to read document from a file. peer is not a native unix/linux command. It comes from Hyperledger fabric (a blockchain service).

    – user344247
    2 days ago







  • 1





    Please show a sample of the input file and show what the -c argument is supposed to look like. I bet a simple jq script is all that's required. That would mean you don't need to break up the file into lines and then combine the lines into a string: jq would do that for you.

    – glenn jackman
    2 days ago











  • @glennjackman That wouldn't make the actual argument to peer shorter in the end, would it?

    – Kusalananda
    2 days ago











  • @glennjackman. I have edited my question and added a few examples. Please don't worry about use of double quotes inside single quotes. I have made sure to have escape characters

    – user344247
    2 days ago














0












0








0








I have the below shell script which reads a file, copies the content of the file to a variable and passes the variable as argument to another command.



declare -a arr=()
while IFS= read -r var
do
arr+=( $var )
done < "accounts.json"
args=''
for j in "$arr[@]"
do
args="$args $j"
done
peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced",'""$args""']'



This works very well when the accounts.json file is small. But I get an error that says "Argument list too long" when the size of accounts.json is too large. I have tried xargs but to no success.



edit 1:



below is example json file with only two rows



["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]


Below is what a peer command would look like with actual data



peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced","["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]"]'









share|improve this question









New contributor




user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have the below shell script which reads a file, copies the content of the file to a variable and passes the variable as argument to another command.



declare -a arr=()
while IFS= read -r var
do
arr+=( $var )
done < "accounts.json"
args=''
for j in "$arr[@]"
do
args="$args $j"
done
peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced",'""$args""']'



This works very well when the accounts.json file is small. But I get an error that says "Argument list too long" when the size of accounts.json is too large. I have tried xargs but to no success.



edit 1:



below is example json file with only two rows



["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]


Below is what a peer command would look like with actual data



peer chaincode invoke -n cc -C channel1 -c '"Args":["InitLedgerAdvanced","["accountID":"C682227132","accountStatus":"1",
"accountID":"C800427392","accountStatus":"1"]"]'






linux bash xargs






share|improve this question









New contributor




user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

41.8k1483142




41.8k1483142






New contributor




user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









user344247user344247

63




63




New contributor




user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user344247 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1





    You would not be able to use xargs here as you (I assume) you need to give the complete JSON document in one go. Is that correct? Can that peer command be made to read the document from a file instead from the command line? (Note: I'm unsure what peer is).

    – Kusalananda
    2 days ago











  • Yes, I need the complete json document in one go. I cannot use the peer command to read document from a file. peer is not a native unix/linux command. It comes from Hyperledger fabric (a blockchain service).

    – user344247
    2 days ago







  • 1





    Please show a sample of the input file and show what the -c argument is supposed to look like. I bet a simple jq script is all that's required. That would mean you don't need to break up the file into lines and then combine the lines into a string: jq would do that for you.

    – glenn jackman
    2 days ago











  • @glennjackman That wouldn't make the actual argument to peer shorter in the end, would it?

    – Kusalananda
    2 days ago











  • @glennjackman. I have edited my question and added a few examples. Please don't worry about use of double quotes inside single quotes. I have made sure to have escape characters

    – user344247
    2 days ago













  • 1





    You would not be able to use xargs here as you (I assume) you need to give the complete JSON document in one go. Is that correct? Can that peer command be made to read the document from a file instead from the command line? (Note: I'm unsure what peer is).

    – Kusalananda
    2 days ago











  • Yes, I need the complete json document in one go. I cannot use the peer command to read document from a file. peer is not a native unix/linux command. It comes from Hyperledger fabric (a blockchain service).

    – user344247
    2 days ago







  • 1





    Please show a sample of the input file and show what the -c argument is supposed to look like. I bet a simple jq script is all that's required. That would mean you don't need to break up the file into lines and then combine the lines into a string: jq would do that for you.

    – glenn jackman
    2 days ago











  • @glennjackman That wouldn't make the actual argument to peer shorter in the end, would it?

    – Kusalananda
    2 days ago











  • @glennjackman. I have edited my question and added a few examples. Please don't worry about use of double quotes inside single quotes. I have made sure to have escape characters

    – user344247
    2 days ago








1




1





You would not be able to use xargs here as you (I assume) you need to give the complete JSON document in one go. Is that correct? Can that peer command be made to read the document from a file instead from the command line? (Note: I'm unsure what peer is).

– Kusalananda
2 days ago





You would not be able to use xargs here as you (I assume) you need to give the complete JSON document in one go. Is that correct? Can that peer command be made to read the document from a file instead from the command line? (Note: I'm unsure what peer is).

– Kusalananda
2 days ago













Yes, I need the complete json document in one go. I cannot use the peer command to read document from a file. peer is not a native unix/linux command. It comes from Hyperledger fabric (a blockchain service).

– user344247
2 days ago






Yes, I need the complete json document in one go. I cannot use the peer command to read document from a file. peer is not a native unix/linux command. It comes from Hyperledger fabric (a blockchain service).

– user344247
2 days ago





1




1





Please show a sample of the input file and show what the -c argument is supposed to look like. I bet a simple jq script is all that's required. That would mean you don't need to break up the file into lines and then combine the lines into a string: jq would do that for you.

– glenn jackman
2 days ago





Please show a sample of the input file and show what the -c argument is supposed to look like. I bet a simple jq script is all that's required. That would mean you don't need to break up the file into lines and then combine the lines into a string: jq would do that for you.

– glenn jackman
2 days ago













@glennjackman That wouldn't make the actual argument to peer shorter in the end, would it?

– Kusalananda
2 days ago





@glennjackman That wouldn't make the actual argument to peer shorter in the end, would it?

– Kusalananda
2 days ago













@glennjackman. I have edited my question and added a few examples. Please don't worry about use of double quotes inside single quotes. I have made sure to have escape characters

– user344247
2 days ago






@glennjackman. I have edited my question and added a few examples. Please don't worry about use of double quotes inside single quotes. I have made sure to have escape characters

– user344247
2 days ago











1 Answer
1






active

oldest

votes


















1














This might work



# slurp the accounts file into a variable
accounts=$(< accounts.json)

# create the json, escaping the accounts quotes along the way
printf -v json '"Args":["InitLedgerAdvanced","%s"]' "$accounts//"/\""

# and invoke the command
peer chaincode invoke -n cc -C channel1 -c "$json"


If that still gives you trouble, you'll have to find a way to pass the -c argument to "peer" via stdin or a file, not as a command line argument.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    user344247 is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509300%2fsolution-for-argument-list-too-long%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This might work



    # slurp the accounts file into a variable
    accounts=$(< accounts.json)

    # create the json, escaping the accounts quotes along the way
    printf -v json '"Args":["InitLedgerAdvanced","%s"]' "$accounts//"/\""

    # and invoke the command
    peer chaincode invoke -n cc -C channel1 -c "$json"


    If that still gives you trouble, you'll have to find a way to pass the -c argument to "peer" via stdin or a file, not as a command line argument.






    share|improve this answer



























      1














      This might work



      # slurp the accounts file into a variable
      accounts=$(< accounts.json)

      # create the json, escaping the accounts quotes along the way
      printf -v json '"Args":["InitLedgerAdvanced","%s"]' "$accounts//"/\""

      # and invoke the command
      peer chaincode invoke -n cc -C channel1 -c "$json"


      If that still gives you trouble, you'll have to find a way to pass the -c argument to "peer" via stdin or a file, not as a command line argument.






      share|improve this answer

























        1












        1








        1







        This might work



        # slurp the accounts file into a variable
        accounts=$(< accounts.json)

        # create the json, escaping the accounts quotes along the way
        printf -v json '"Args":["InitLedgerAdvanced","%s"]' "$accounts//"/\""

        # and invoke the command
        peer chaincode invoke -n cc -C channel1 -c "$json"


        If that still gives you trouble, you'll have to find a way to pass the -c argument to "peer" via stdin or a file, not as a command line argument.






        share|improve this answer













        This might work



        # slurp the accounts file into a variable
        accounts=$(< accounts.json)

        # create the json, escaping the accounts quotes along the way
        printf -v json '"Args":["InitLedgerAdvanced","%s"]' "$accounts//"/\""

        # and invoke the command
        peer chaincode invoke -n cc -C channel1 -c "$json"


        If that still gives you trouble, you'll have to find a way to pass the -c argument to "peer" via stdin or a file, not as a command line argument.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        glenn jackmanglenn jackman

        52.9k573114




        52.9k573114




















            user344247 is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            user344247 is a new contributor. Be nice, and check out our Code of Conduct.












            user344247 is a new contributor. Be nice, and check out our Code of Conduct.











            user344247 is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f509300%2fsolution-for-argument-list-too-long%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

            Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

            Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.