2

The command I'm trying to run:

mdb-tables davidoff.mdb | xargs -I {} mdb-export davidoff.mdb {} > {}.csv

mdb-export takes two arguments, I'm trying to pipe the second one. And then I want each one to be written to a file.

This won't work. Even when I remove the > {}.csv there is still an error:

Error: Table {} does not exist in this database.

Shell is zsh

example output from first part:

% mdb-tables davidoff.mdb
anatomypiclink bugs bugseverity bugtype classifications Diseases docaccess docaccesstype docassignments docclassifications docdetails docnotes docpicturelink docqa docs doctype keypicturelink keywords links logons mediatype navdoclinks navimagelinks navstructures organs Paste Errors pictureclassifications pictures picturetype qub3_queries_que qub3_relations_rel qub3_settings_set quotes references sequencelinks sequences subDocType videos dictionarytable doclinks docstatus media docs_ExportErrors

As a test case, I was able to make this work: printf "1\n2\n3\n" | xargs -I touch {}

Why is it that I cannot use replstr as a second argument?

9
  • xargs --verbose will show the command that's going to be executed after substitution. Can you check that and see how it differs from what you expect?
    – Haxiel
    Oct 28 '20 at 17:58
  • 1
    The > {}.csv will happen just once, outside xargs, and will redirect the output of all the mdb-export ... commands into a single file named exactly {}.csv.
    – user414777
    Oct 28 '20 at 18:15
  • 1
    Thanks for the update. From the manual, I read that "You must specify a delimiter (-d) if you intend on piping the output of mdb-tables to a program such as awk or cut." This may be one of those pipe aware programs that output one thing in a terminal and another thing in a pipe.
    – Quasímodo
    Oct 28 '20 at 21:45
  • 1
    What system is that? What did the echo-prepended, dry-run command from my comment print?
    – user414777
    Oct 29 '20 at 0:03
  • 1
    I guess the question about your system meant "what operating system are you using?". E.g. a Linux distribution, macOS, the Windows Subsystem for Linux, ...? Also, which version of xargs are you using?
    – fra-san
    Oct 29 '20 at 10:22
0

Some versions of xargs on some systems places a 255 byte limit on arguments; if this is the case, it should be mentioned in the man page in the section on the -I argument. When an argument is greater than this limit, the placeholder isn't replaced. mdb-tables is outputting the table name list as a single line of 500 bytes.

As Quasímodo mentions, you can use the -d "\n" argument to break the table names into separate lines; you can also use -1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.