Questions tagged [for]

A tag to denote any questions relating to for loops

Filter by
Sorted by
Tagged with
-1 votes
0 answers
16 views

Assign values ​to each column of the matrix in python [migrated]

Q = np.zeros((5,5)) ccs = [1,2,3,4,5] q = [[-0.48198762] [-0.155757 ] [ 0.79430319] [-0.25273778] [-0.22053059]] for cc in ccs: Q[:,(int(cc)-1)] = np.transpose(q) I run the code in ipython, ...
Away's user avatar
  • 1
1 vote
2 answers
129 views

How to extract and delete contents of a zip archive simultaneously?

I want to download and extract a large zip archive (>180 GB) containing multiple small files of a single file format onto an SSD, but I don't have enough storage for both the zip archive and the ...
Kumaresh Balaji Sundararajan's user avatar
0 votes
2 answers
72 views

Pass multiple arguments from single line from a text file to teminal

I have a python program that requires 2 arguments input-file and output-file. It reads input-file and creates a copy of that file with some modifications in the output-file. I created a text file with ...
Data Engineer's user avatar
0 votes
2 answers
96 views

Is there a syntax for a "for" loop over words or lines in a variable, that will work unmofdified in both bourne shell and zsh?

I have a variable that contains a list of strings, one per line, to be looped over in a for...in...do...done command. I move regularly between bourne shell and zsh. As far as I can understand it, zsh ...
Stilez's user avatar
  • 1,221
0 votes
1 answer
123 views

Recursively fix corrupted video files with ffmpeg

I think I'm pretty close to having a code which will start at a directory, then spit out a fixed copy, using fd (instead of find) and ffmpeg. I have written the if statement here as psudo-code: for i ...
1toneboy's user avatar
  • 101
0 votes
3 answers
303 views

for loop through multiple directories and multiple files

I want to check if each .bam file is accompanied with a .bai file. So if clean_xyz_1.sorted.bam is present clean_xyx_1.sorted.bam.bai should also be present. Each file has a variable string in the ...
user3637557's user avatar
0 votes
2 answers
57 views

For loop with Multiple IF condition's in Shell scripting

Firstly , In the /tmp/test file path I have the below directories amb bmb cmb By running the find command, I am getting the below list of files inside these three directories: amb/eng/canon.amb bmb/...
afrin's user avatar
  • 51
1 vote
0 answers
30 views

Do I have to write a shell script purely to access bash for loops inside of say watch? [duplicate]

I'd like to monitor apps that have inotify instance in real-time with watch using something similar to: watch "for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | ...
Tomachi's user avatar
  • 111
2 votes
2 answers
369 views

For loop through a variable vector

I have a for loop and case statements. The for loop has quite a bit element list and the case statement will assign an 1D array or a vector. These values will be used in for loop after. I have the ...
BircanA's user avatar
  • 21
0 votes
3 answers
101 views

"for i in" loop with multiple vars

I have two variables VAR1="1 2 3" VAR2="Bob Tom Kate" I want to echo something like this but I don't know how to use multiple variables in a loop: 1 for Bob 2 for Tom 3 for Kate ...
trilisser's user avatar
  • 101
2 votes
3 answers
2k views

How to loop through all the files in a directory and print all the file names, like the command tree

How can I mimic the tree command and iterate through all the files and subdirectories of a directory and echo all the file names? I thought that a subdirectory within a directory is still counted as a ...
John Smith's user avatar
0 votes
2 answers
72 views

Unix. Run script across multiple dirs on specific files, where pathname has regex

I want to make a bash script (split.sh) that iterates across multiple dirs with same suffix, and then runs a function for specific files within them. I am almost there: #!/bin/bash path="/mypath/...
Lucas's user avatar
  • 99
0 votes
1 answer
28 views

Why does the test command apparently choke on a for loop variable?

I want to determine all broken symlinks within a directory. In ignorance of a better solution, I tried this simple bash one-liner (bash version is 4.2.46, which may be worth mentioning because it's a ...
andreee's user avatar
  • 193
0 votes
1 answer
53 views

looping through directories in bash skipping a particular directory name

I am trying to loop through directories within a given folder and I want to skip a particular directory name. I have written this bash script to do it, but this is giving me errors. Please tell me ...
user3138373's user avatar
  • 2,491
-4 votes
1 answer
82 views

Awk commands for each arg

I have an awk implementation in a bash script which I want to run for each function arg using a do loop. Each arg is composed of a multiline string. for arg in "$@"; do done Here is the ...
Vera's user avatar
  • 1,183
1 vote
1 answer
62 views

How to iterate over a directory for files without including sub-directories in Bash

I need to parse through a directory that contains files and subdirectories however I am unable to use the find command. The for loop is supposed to go through each file and compare it to another ...
IMPNick's user avatar
  • 11
0 votes
3 answers
220 views

extracting multiple tar files in folders with their corresponding file names

Hi I'm having a multiple tar files like 1.tar 2.tar 3.tar..etc and i wanted to extract them to corresponding folders i.e 1.tar to a folder named 1 and so on... my trial was like the following: for ...
Ahmed Moselhi's user avatar
0 votes
2 answers
64 views

for loop with grep not returning record by record [closed]

I have the below for loop in my shell script: #!bin/ksh touch output.dat IFS=">>>" i=0 for stm in `grep "cpdctl dsjob run-pipeline --project " input_file` do echo "...
Jerry Jose James's user avatar
0 votes
1 answer
98 views

How to exit a FOR loop on detecton of "error" stream using TAIL

I have a "for" loop which passes the results to a file called "results" Occasionally an error stream is detected and the loop continues trying within the loop for a number of times ...
Leighton 's user avatar
0 votes
1 answer
81 views

How to copy some but not all of the files in a directory based on patterns in the file name?

I have a long list of files named according to the following pattern: S901_S1_fastq.gz S902_S2_fastq.gz S903_S3_fastq.gz S904_S4_fastq.gz etc. Because these files correspond to different experimental ...
Clayton Tracey's user avatar
0 votes
0 answers
24 views

for loop with a list ... entities with spaces [duplicate]

As a intermediate step I want to produce one line per string in '' with below script #!/usr/bin/env/ bash TOMCAT_OFF=('16:00 19.01.2023' '16:00 21.02.2023' '16:00 15.02.2023') for i in ${TOMCAT_OFF[@...
vrms's user avatar
  • 139
0 votes
1 answer
67 views

Errors appending text with `sed`

I have a podman-compose file: version: "3.8" services: kiwix-serve: image: docker.io/kiwix/kiwix-serve:3.3.0-1 volumes: - kiwix_data:/data - /home/meijin3/zim/...
meijin3's user avatar
  • 139
0 votes
0 answers
51 views

Nested for loop inside an ssh -t for loop command

I've been trying to save some time by creating a loop to edit ifcfg files using the sed command. For testing I started by trying the below loop: for k in `cat *FILE CONTAINING HOSTNAME*`; do echo $k; ...
jodell's user avatar
  • 1
1 vote
1 answer
412 views

Understanding timestamps in a GNU Parallel --joblog output

Does GNU Parallel start a batch of as many jobs as possible (the number of jobs started being governed by GNU Parallel internals or/and the -j option along with given parameters), and once complete, ...
Nikos Alexandris's user avatar
0 votes
1 answer
694 views

How to create a text file for each files found in a directory?

I'm new to unix and I'm having a hard time doing this loop. I have a directory with a list of files and I'm able to list all of those files in a text file. I have a text file that contains the ...
Philippe Javier's user avatar
0 votes
2 answers
94 views

Using variables inside the for loop in shell [duplicate]

I'd like to use variables inside the for loop in shell. My current code: VAA="1st_first" VAB="2nd_second" VAC="3rd_third" for i in VAA VAB VAC; do if [[ "${i}...
Feriman's user avatar
  • 939
2 votes
1 answer
653 views

GNU Parallel with -j -N still uses one CPU

How can I get reasonable parallelisation on multi-core nodes without saturating resources? As in many other similar questions, the question is really how to learn to tweak GNU Parallel to get ...
Nikos Alexandris's user avatar
7 votes
3 answers
668 views

How can I assign the output of a command to different variables in each loop iteration?

I have a script something like this: for chain in http https ssh do iptables -nvxL $chain | tail -1 | awk '{print $2}' done But what I actually want to do is capture the output of the iptables ...
Aditya K's user avatar
  • 2,000
0 votes
1 answer
401 views

For loop in bash to input a new file in directory

For context: I am running Prokka (as a novice bioinformatician with no Prokka and little Bash experience) and I have multiple FASTA files. I have been told I need to produce a Bash loop that will ...
notknowingyet's user avatar
0 votes
2 answers
85 views

Loop over space delimited PIDs, get number of open file handles

How may I loop over a set of PIDs delimited by spaces? I think I remember the first step is like making each element its own row? For my Firefox sessions they are quite a few PIDs: $ pidof firefox ...
von spotz's user avatar
  • 405
0 votes
4 answers
594 views

execute a command recursively on the files of a folder in the matching location, not in the original one

I want to recursively convert files from .docx to .doc in a folder. The problem is that all the output files are created in the folder where I run the following command, not in the location of the ...
fich's user avatar
  • 290
0 votes
0 answers
41 views

Autofill "y" in for loop in bash [duplicate]

I'm very new to bash and I'm trying to run script in python I have. When the script runs, the first thing it prompt is y/n question, and I would like to automate this part so I can run it ...
Reut's user avatar
  • 101
0 votes
2 answers
1k views

Looping over dirs using `find . -depth 1 -type d`

I've been given a script to run, but it produces an error when calling find . -depth 1 -type d. It produces the following error, find: paths must precede expression: `1' This is the line in which it ...
wardz's user avatar
  • 103
0 votes
1 answer
163 views

Variable is always empty regardless of the loop technique I use

I have a file called dependencies and its content is: blog forms geo ticketing And I have this build.sh script in which I need to loop over them. This build script would be run inside a docker ...
Saeed Neamati's user avatar
1 vote
1 answer
651 views

How to make a script to rename images and videos with the date of modification?

I have a gallery folder with images and videos in it named in unwanted format. I want to make a script that scans through each file in that directory and when it finds an image or a video to rename it ...
userbash654's user avatar
0 votes
2 answers
142 views

How to rename numerically titled file names by 1 digit?

This feels so simple, and yet I'm entirely stumped. Needless to say I am absolutely new to this. I have a directory with files numerically numbered from 000 to 020. I would like to rename these files ...
Doodling's user avatar
0 votes
1 answer
35 views

`for in` command filename expension issue [duplicate]

I have a bash script with:- for i in *.x *.y *.z *.a *.b *.c do echo "$i" done If there are no files matching the pattern *.y then the variable i has the value *.y. When this happens, ...
user223364's user avatar
1 vote
1 answer
1k views

Need to capture exit code of pylint command using find in Github actions

I am trying to implement a python linter using pylint. But I am getting the score of each python file and also displaying the suggestion to improve the score but I am also looking to terminate the ...
sidharth vijayakumar's user avatar
0 votes
1 answer
265 views

Create directory using filenames and move the files to its respective folder

My question is a bit different than: Create directory using filenames and move the files to its repective folder Since in the same folder I have two similar copy of each file like: 001.txt and 001(1)....
Maxfield's user avatar
  • 151
1 vote
2 answers
259 views

How to make a for loop to read directory names with spaces in them?

I need to create a script to scan folders in a directory and take the name of each folder, make a .txt file, name it with the name of the folder and put inside that folder. For example: A directory ...
guest456782's user avatar
0 votes
1 answer
118 views

for loop parsing of ls and the magic behind *

I know that the following is bad: for i in `ls -1 *.MOV` ;do ... and that the proper syntax is for i in *.MOV ;do ... But what are the mechanics behind it? I mean, what part of *.MOV tells the ...
mikem's user avatar
  • 816
0 votes
1 answer
57 views

bash: different behaviour of script and in terminal (loop over files)

I'm trying to loop over files with having different searching conditions based on the folder which I used with a case statement. basically it's: #!/bin/bash case folder in "Testordner") ...
Caro's user avatar
  • 3
8 votes
5 answers
1k views

bash loop to replace middle of string after a certain character

I have 120 files (genomes.faa) that all have headers between each sequence >GENOME1_00001 HYPOTHETICAL PROTEIN A NQFTIAQSQVGLEDALLDL >GENOME1_00002 HYPOTHETICAL PROTEIN B NQFTIAQSQVGLEDALLDL &...
Goodolgab's user avatar
4 votes
2 answers
891 views

How to run a loop inside sh -c

I'm having trouble understanding what I need to escape when using sh -c. Let's say I want to run the for loop for i in {1..4}; do echo $i; done. By itself, this works fine. If I pass it to eval, I ...
Christopher's user avatar
1 vote
1 answer
3k views

How to Store the Output of a for Loop to a Variable

I have the following shell code: for value in 10 5 27 33 14 25 do echo $value done But what if I want to manipulate the output later? I want to store the entire output in one variable. Is ...
Amarakon's user avatar
  • 303
1 vote
3 answers
107 views

Different $RANDOM results in sed when reading lines in multiple files

I'm trying to run a command that will read multiple files in a directory, look at each line of each file, and whenever it reads a specific string ("gene_height") on any line it replaces 2 ...
the_pocket_of_big_noob's user avatar
0 votes
1 answer
443 views

Looping through variables which is an output of another command

Hello I am learning Scripting here. I am trying to write a simple script using the 'for' loop. I have hundreds of folders in a folder called user. if i run this command i get a list of folders that i ...
ranjit abraham's user avatar
1 vote
2 answers
901 views

How might I execute this nested for loop in parallel?

#!/usr/bin/bash TARGETS=( "81.176.235.2" "81.176.70.2" "78.41.109.7" ) myIPs=( "185.164.100.1" "185.164.100.2" "185.164.100.3" "185....
John Smith's user avatar
1 vote
1 answer
247 views

Delete folders from a directory once it's sbatch`ed in a for loop?

I am running a command using sbatch for a tool on the server, that takes a lot of space. The command uses some directories (some files) from a main directory(tq_first) in a for loop. I was wondering ...
Echo94's user avatar
  • 13
1 vote
1 answer
210 views

cannot figure out why the file will not copy

I am trying to write a program which i can reuse for copying content into multiple directories. But for the life of it i cannot figure out why the program does not work and is throwing this error. I ...
ranjit abraham's user avatar

1
2 3 4 5
10