1,332 questions
3
votes
5
answers
188
views
`printf` and `xargs` in a `for` loop
I want to produce this output:
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
For that I created this script:
(Based on https://stackoverflow.com/a/23961301/22133250)
...
-3
votes
1
answer
163
views
How can I dissect a shell 1-liner workflow to understand what this git command does? [closed]
I am updating an existing pipeline on GitLab that creates an automatic cascade on GitLab.
When a merge request is merged, the pipeline is triggered to perform an automatic commit to a lower branch (if ...
1
vote
1
answer
36
views
The strange behavior of xargs with option -L [closed]
echo -e "a b \nc d"|xargs -L1
a b c d
echo -e "a b\nc d"|xargs -L1
a b
c d
see the above code. The man page says that "-Lmax-line means Use at most max-lines nonblank input ...
1
vote
1
answer
70
views
Switching from xargs to parallel solely to get --joblog output, all else the same. How?"
I need to grab the exit status from a command that I run via xargs. Since that's not possible it's recommended to use parallel. Some documentation suggests that it's often as simple as swapping the ...
0
votes
2
answers
75
views
Manipulating current input string of xargs in makefile target
I'm trying to write a makefile target using xargs, but the implementation is a bit over my head. Here's the what I would like:
dryrun:
@mkdir -p $(OUTPUT_DIR)
@if test -e $(MY_DIST); then \
...
-2
votes
1
answer
98
views
What's wrong with lsusb | awk '{print $6}' | xargs --null lsusb -s [closed]
Command 1:
lsusb | awk '{print $6}'
Output 1:
1d6b:0002
0627:0001
0627:0001
0627:0001
0409:55aa
46f4:0001
1d6b:0003
1d6b:0002
1d6b:0003
Command 2:
lsusb | awk '{print $6}' | xargs
Output 2:
1d6b:...
1
vote
0
answers
106
views
Refining the output of the chain of commands: lsmod | awk '{print $1}' | xargs modinfo -p
The output of the command chain provides a list of all the parameters of the modules. I have executed the command chain in bash under fedora 40.
The first command to show the Linux OS release:
cat /...
0
votes
1
answer
64
views
Entering into the last modified sub-directory in a directory in linux
I have a dir in which I keep adding new dirs from a script. I want to enter that new sub-dir directly rather that always manually doing eza --sort=modified then copy pasting that name then cd into ...
0
votes
1
answer
55
views
How to handle file name with space in it with bash [duplicate]
I'm referring to the following command from the book "Linux shell scripting cookbook".
find . -name '*.txt' | xargs -I ^ sh -c "echo -ne '\n ^: '; grep arg ^"
And have the ...
0
votes
2
answers
134
views
xargs cannot run with -n1 and -I together? [closed]
I need to create sub-folders under in selected_images with identical structure as download_async/. I used this command:
ls download_resave/ | xargs -n1 -t -I{} mkdir -p select_images/{}
But I know ...
-1
votes
4
answers
151
views
Process tab-separated (tsv) file with xargs while preserving quotes
I have a tab-separated-file myfile.tsv of form:
"a" "b"
"c" "d"
How can I process it with xargs (i.e. what args I need to pass) to pass these fields ...
0
votes
3
answers
82
views
Use --replace string in xargs but still use multiple arguments per command
I want to pipe plocate output (a list of paths) to another command using xargs.
I need to use the -I{} replacement but I want to run one single command with all args, not one command per arg.
The ...
0
votes
1
answer
87
views
Use particular values of each row of csv for command path argument [closed]
Not sure why I can't find this answer anywhere.
Input CSV:
201800001779830000,"17798320181.pdf",,,159.0,5371.0,,,,,,2019,"{}",2022-08-25 12:58:20.928,2022-08-26 03:13:35.292,...
0
votes
1
answer
67
views
xargs not recognzing the --verbose option inside docker command script
I am using the solution @Krzysztof proposes in Restarting an unhealthy docker container based on healthcheck. I have made one change to the original, adding --verbose so that the command docker ...
0
votes
3
answers
69
views
TO find word count file by file
Is it possible to determine the number of times a particular word appears in multiple files - file by file - using grep
the "-c" option but this returns the number of matching lines the ...
0
votes
1
answer
143
views
Curl list of links and save files according to URL hierarchy
From the first API call, a JSON response is returned which includes a bunch of links. I want to curl each link, and download the file to a location based on the last 3 path segments.
For example, if ...
3
votes
2
answers
195
views
Wrong result from xargs du | tail
I'm trying to calculate the size of an rsync backup before executing it:
du -hs -- $(rsync -avn --exclude --delete $source $target | grep / | grep -v " bytes/sec" | grep -v "deleting &...
0
votes
3
answers
143
views
Pass multiple arguments to single command in custom position xargs
I want execute a command where I have the args as single string but they need to be in a custom position. E.g. in the following example I want the args to be positioned before any fixed args that I ...
0
votes
0
answers
62
views
Visual Studio Terminal Error When Connected to Ubuntu 22.04 WSL
I use WSL for development. When I start Visual Studio Code and connect it to an Ubuntu 22.04 WSL instance, I always get this error when launching VS's Terminal:
xargs: unmatched double quote; by ...
0
votes
1
answer
116
views
How do I speed up Git submodule init + update
I have a repo with a lot of submodules, and it takes a long time to initialise all of them from a fresh checkout.
git submodule update --init
seems to do everything in series, when the operation ...
0
votes
1
answer
64
views
Is there a way to take the output of xargs and combine any stderr and stdout into a single line so there is only one line per command run?
I have a long list of symbolic links to python venvs that I would like to run the --version flag on. Some of the links are broken and some of the Python binaries require other versions of glibc than ...
0
votes
2
answers
323
views
Tar piping creates error during run and stops
I am running a larger copy job online.
I am using tar for that piped to xargs.
My command looks like this:
tar cvf - --sort=name --ignore-failed-read -C /pathto/source . | pv | xargs -n 1 -P 32 $(tar ...
0
votes
0
answers
115
views
Move large files(in GBs) in parallel
I have a use case, where we need to move large files from openshift to another server. Each files are in GBs. Total size of files were few Terabytes. I'm using oc rsync/cp feature to move files.But it'...
0
votes
1
answer
112
views
grep for string and open matching files in text editor
I wasn't able to find an answer for this simple question. I had a solution for it years ago and I think it involved something like { }, but I've totally forgotten now.
I'm looking to grep for a ...
1
vote
1
answer
322
views
find and grep - Suppress terminated by signal 13
If I want to find only first match of command grep I use this:
find -name "*.jar" | xargs grep -al myText | head -1
And it's work just fine.
But it's also show the next message:
xargs: grep:...
0
votes
4
answers
88
views
pipe stdio to a function
Noob question!
I've got a function on the command line that takes parameters
sqr() { echo $(( $1 * $1 )) ; }
sqr 4 echos 16. fine.
Now I want to pipe an output to this function
echo 4 | sqr
I get &...
0
votes
1
answer
54
views
What is the difference between xargs with a single command and with a complex command?
I am contemplating about some nuances of xargs.
Reading the question:
(
what is the difference between -L and -n in xargs
)
I feel irritated.
When I use a multiple argument command sh -c "...&...
0
votes
4
answers
132
views
Bash: How to extract parent directory of 3 files at a time
I have file names like this:
/foo/bar/bazz/JMA01023D_E07/JMA01023D_E07_EKDL230054768-1A_22HFKNLT3_L4_1.fq.gz
/foo/bar/bazz/JMA01023D_E08/JMA01023D_E08_EKDL230054768-1A_22HFKNLT3_L4_1.fq.gz
/foo/bar/...
0
votes
0
answers
114
views
Xargs to cd for files with spaces on mac
I have referred to quite a few answers on SO but haven't been able to figure out a solution for this.
What I am trying to do is to have a cd command that uses fzf to match the directory to jump into. ...
1
vote
2
answers
310
views
Strange xargs Behavior with special characters within variable
I'm running into strange behavior with xargs in a bash script where the replacement is not working anymore when placing it in the middle of a variable with special characters. Please see the following:...
0
votes
2
answers
150
views
Docker ps command into XARGS command to check and auto restart unhealthy containers
docker ps -f health=unhealthy --format "docker restart {{.ID}}" | xargs --no-run-if-empty -t docker restart
output is :
docker restart docker restart 7c20974e2b02
7c20974e2b02
Error ...
0
votes
2
answers
642
views
Redirecting xargs input as stdin stream instead of argument
Sometimes it's useful to write an xargs command that begins with xargs -I {} 'echo {} | [rest of command]' in order to redirect the argument as a pipe.
however, for large arguments, you will ...
1
vote
2
answers
78
views
Adding extra commands inbetween xargs commands
I have a bash script like the following example that attempts to first list a bunch of items, then run a command on those items individually:
customListCommand | xargs -P 10 -n1 echo
If ...
1
vote
1
answer
36
views
Bash Script: result of xargs assigned to variable loses all but one item
I'm running a bash script that greps through files to identify tests, then it should output the results to a string and store in a variable. When the command is run on its own it echoes out all the ...
0
votes
0
answers
133
views
Best way to set up embarrassingly parallel code for workstation and HPC
I'm looking for the most versatile/easiest way to run an embarrassingly parallel code with changing inputs.
I want the final solution to be able to run on a workstation (no PBS available), but also ...
0
votes
3
answers
225
views
Batch rename spaces in filenames to underscore
I have a directory called windows which contains files with names containing spaces. I want to replace the spaces in file names with underscores _. I need to correct all file names in the windows ...
1
vote
1
answer
119
views
Using find to pass multiple files to awk and redirect result into one output file
I have an awk script that processes files passed in. It runs on one input file and redirects into one output file...
awk -f solar.awk ./PerformanceData_2023-08-02_02-02-17/tmp_YdayData.txt > output....
0
votes
2
answers
101
views
Why does ''xargs bash -vc "$(declare -f {})"'' not work?
Bash 3.2.57 running on OSX.
Following displays the function definition as expected.
declare -f my_bash_function
Following works as well but only with -v flag.
bash -vc "$(declare -f ...
2
votes
2
answers
675
views
remove file extension with basename when using xargs
I would like to use xargs to run a command on a number of files where the output from the command has a different file extension. For the example below I am using echo as a dummy command.
ls *.las | ...
4
votes
2
answers
106
views
Bash script to remove folders older than X, but skipping newest N... Compatible with special characters in path
I am writing a backup script in bash and want to delete all backups older than X days, while leaving at least the newest N backups.
This seems so simple, yet I have not been able to find a solution to ...
1
vote
3
answers
98
views
bash one-liner/script to execute a command on files that do not have an associated file
The following executes do_x.sh on all files of type a_???.json recursively. However, I would like to do the same on a subset of these files that do not have a corresponding file with the same name and ...
2
votes
2
answers
133
views
how to sort a huge number of files with an obscure program that only outputs their ordering
A colleague of mine wanted to run a FORTRAN program that takes files arguments and outputs their ordering (best first) against some biophysicochemical criterion. What he needed were the 10 best ...
-2
votes
1
answer
230
views
How to solve issue Argument list too long in grep command? [closed]
How to solve issue Argument list too long in grep command?
I need to execute grep command
grep '^ORA' '/log/bssuser/CDR/Postpaid_CDR_Log/'*.log > output.txt
I have error :
-bash: /usr/bin/xargs: ...
0
votes
2
answers
115
views
Escape cron job definition when exporting env variables along with xargs
I'm trying to write a script that requires to export some env variables by reading the values and names from an .env file.
Here's an example of the .env file:
INSTANCE_PROFILE_ARN=arn:aws:iam::...
0
votes
1
answer
213
views
Xargs: Alias substitution fails despite expanding the alias
I have the following command:
fd --type f -0 --full-path $HOME/something/something_inside_something | fzf --read0 --print0 --exit-0 --preview 'bat {1}' | xargs -r -0 vim
Where vim is an alias of:
...
1
vote
1
answer
128
views
Tag every branch with prefix and delete branch
I realized that somehow after a while my team and i collected ~80 stale branches in one repo. The history should be kept.
So I thought just tag every branch with a prefix "archive/".
But i ...
0
votes
1
answer
93
views
how do I concatenate '/' to words read from input with xargs before passing them as arguments to a command?
I have saved a list of file paths to a text file and unfortunately the leading '/' gets dropped in the process from each path turning the file path from an absolute to a relative one. I am using <...
0
votes
0
answers
166
views
c6.s081 lab1 xargs:I don't know why the program below can't get the answer?
when I was finishing the c6.s081(2021) lab1 xargs, I found a function from other person which is below:
#include "kernel/types.h"
#include "kernel/param.h"
#include "user/user....
7
votes
1
answer
5k
views
Multi-threading with xargs warning xargs: warning: options --max-args and --replace/-I/-i are mutually exclusive, ignoring previous --max-args value
I have an xargs command in a bash script. The script runs, but this warning is returned
xargs: warning: options --max-args and --replace/-I/-i are mutually exclusive, ignoring previous --max-args ...
0
votes
1
answer
64
views
Quoting filenames in multi-step xargs bash pipeline
I am creating a bash pipeline where I want to find files that contain specific text and then do something with only those files. I can successfully get the list of files using the find/xargs pairing:
...