xargs

Putting the data passed to xargs twice in one line

我是研究僧i 提交于 2019-12-12 14:53:26
问题 tmp-file contains: database_1 database_2 database_3 I want to run a command like "mysqldump DATABASE > database.sql && gzip database.sql" for each line in the above file. I've got as far as cat /tmp/database-list | xargs -L 1 mysqldump -u root -p I guess I want to know how to put the data passed to xargs in more than once (and not just on the end) EDIT: the following command will dump each database into its own .sql file, then gzip them. mysql -u root -pPASSWORD -B -e 'show databases' | sed

Renaming a series of files

无人久伴 提交于 2019-12-12 09:00:45
问题 Trying to rename a series of files on a linux server. Finding the files I want is easy: find . -type f -wholename \*.mbox Of course, being mbox files, some of them have spaces in the names, so it becomes: find . -type f -wholename \*.mbox -print0 I'm piping to xargs so that I can rename the files: find . -type f -wholename \*.mbox -print0 | xargs -0 -I{} echo ${"{}"/.mbox/} The echo should return something like INBOX, given INBOX.mbox, however, bash complains: bash: ${"{}"/.mbox/}: bad

Reverse newline tokenization in one-token per line files? - Unix

荒凉一梦 提交于 2019-12-12 01:04:28
问题 How to separate tokens in line using Unix? showed that a file is tokenizable using sed or xargs . Is there a way to do the reverse? [in:] some sentences are like this. some sentences foo bar that [out]: some sentences are like this. some sentences foo bar that The only delimiter per sentence is the \n\n . I could have done the following in python, but is there a unix way? def per_section(it): """ Read a file and yield sections using empty line as delimiter """ section = [] for line in it: if

Why would xargs split input on spaces and how to resolve it?

血红的双手。 提交于 2019-12-11 17:18:40
问题 In the following bash script, I'm capturing file a file list from a path into a variable and then passing it on into xargs for further operations. I've found that simply echo ing the variable gives each line with spaces appropriately with a newline terminator for each line. However when I printf or echo this over to xargs , I'm finding that xargs appears to be splitting the input of each line by spaces as well. I'll illustrate with the following example with comments including the result I'm

How can heredocs be used with xargs?

左心房为你撑大大i 提交于 2019-12-11 04:26:52
问题 Background I'm looking to strip any # TODO comments from some python source code files output by git archive before sending it off. I'm looking to do so from a script that will be run from a variety of *nix OSes, so it should be as POSIX-compliant as possible. I'm aware that find -print0 and xargs -0 aren't in the base spec, but they appear to be common enough that I'm fine with using them (unless a better alternative exists). I'm using ed due to sed -i not being in the base spec for in-place

Making xargs work in Cygwin

一个人想着一个人 提交于 2019-12-11 03:49:35
问题 Linux/bash, taking the list of lines on input and using xargs to work on each line: % ls -1 --color=never | xargs -I{} echo {} a b c Cygwin, take 1: $ ls -1 --color=never | xargs -I{} echo {} xargs: invalid option -- I Usage: xargs [-0prtx] [-e[eof-str]] [-i[replace-str]] [-l[max-lines]] [-n max-args] [-s max-chars] [-P max-procs] [--null] [--eof[=eof-str]] [--replace[=replace-str]] [--max-lines[=max-lines]] [--interactive] [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-procs]

How do I run find and cp commands concurrently in Linux?

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:47:13
问题 How do I run find and cp commands concurrently? I have tried this: find -name "*pdf*" | xargs cp $1 ./ But it doesn't work. 回答1: Use -exec option: find ./ -name "*pdf*" -exec cp -t . {} \+ The {} is replaced with the current file names being processed. From the man page for find : -exec command {} + ...the command line is built by appending each selected file name at the end.. The command line is built in much the same way that xargs builds its command lines. Note the use of -t (target

Parallel processing with xargs in bash

岁酱吖の 提交于 2019-12-10 16:09:19
问题 I had a small script where I would source into each openstack's tenant and fetch some output with the help of python. It took too long for the reports to get generated and I was suggested to use xargs . My earlier code was like below. #!/bin/bash cd /scripts/cloud01/floating_list rm -rf ./reports/openstack_reports/ mkdir -p ./reports/openstack_reports/ source ../creds/base for tenant in A B C D E F G H I J K L M N O P Q R S T do source ../creds/$tenant python ../tools/openstack_resource_list

Using xargs to assign stdin to a variable

走远了吗. 提交于 2019-12-10 15:59:43
问题 All that I really want to do is make sure everything in a pipeline succeeded and assign the last stdin to a variable. Consider the following dumbed down scenario: x=`exit 1|cat` When I run declare -a , I see this: declare -a PIPESTATUS='([0]="0")' I need some way to notice the exit 1 , so I converted it to this: exit 1|cat|xargs -I {} x={} And declare -a gave me: declare -a PIPESTATUS='([0]="1" [1]="0" [2]="0")' That is what I wanted, so I tried to see what would happen if the exit 1 didn't

xargs just working with built in functions

六月ゝ 毕业季﹏ 提交于 2019-12-10 10:22:17
问题 I am trying to speed up the processing of a database. I migrated towards xargs. But I'm seriously stuck. Piping a list of arguments to xargs does not work if the command invoked by xargs isn't a built in. I can't figure out why. Here is my code: #!/bin/bash list='foo bar' test(){ echo "$1" } echo "$list" | tr '\012' '\000' | xargs -0 -n1 -I '{}' 'test' {} So there is no output at all. And test function never gets executed. But if I replace "test" in the "xargs" command with "echo" or "printf"