Questions tagged [for]

A tag to denote any questions relating to for loops

Filter by
Sorted by
Tagged with
2
votes
2answers
68 views

How can I edit and combine multiple matching files with one loop?

*edit: I've decided to append all the outputs to a single file. I have 40 csv files that I need to edit. 20 have matching format and the names only differ by one character e.g., docA.csv, docB.csv, ...
0
votes
0answers
16 views

Loop through files from current directory and subdirectories [duplicate]

I'm trying to loop through each files from current directory and subdirectories. But the problem is file names with blank-space are getting treated as separate files. How do I prevent that. I want to ...
0
votes
1answer
20 views

setting number of integers for unlimited argumments

I'm not quite sure what I'm doing here but I need to be able to get an unlimited number of integers to be provided as arguments so far I have for sum in $@; do sum=$(($1 + $2 + $3)) done echo ...
0
votes
1answer
18 views

How to loop over subdirectories and perform action while ignoring spaces in file names [duplicate]

I have the below folder structure in Linux env: |-- Fixed_Zip | |-- ipython_notebooks | | |-- notebook editor for compute_0anXhGEj.ipynb | | |-- notebook editor for compute_aucScores.ipynb | ...
0
votes
2answers
93 views

Shell script with a for loop and an “array”

How can I use this sh script with for loop and an array. I would like to call create condition for quality gate creation of sonarqube with a for loop. Example: #!/bin/bash --login echo "Creating ...
0
votes
1answer
25 views

Creating directories inside a directory, from variable values, to redirect output from sed

I am trying to take a file, modify this file by using a value from a for loop (using sed) and redirecting it to a directory that has been created during the same for loop. Original file > Make ...
-1
votes
1answer
52 views

For loop in bash via ssh for parallel network

I have 4 CPUs in a parallel network and want to run N jobs on each of those 4 CPUs. I also want to divide N number of jobs into X jobs and run that as a loop on each of the 4 CPUs. The bash script ...
0
votes
2answers
138 views

How to sample without replacement from a script that randomly extracts 200characters using shuf?

I have this script that extracts 200 random characters from a set: #!/usr/bin/bash n=$(stat -c "%s" newfile.txt) r=$(shuf -i1-"$((n-200+1))" -n1) < newfile.txt tail -c+"$r&...
0
votes
4answers
83 views

Bash - looping through specified folders to find empty files

I want to loop through a set of folders, specified within the script and print all files that are empty. I use this script: array=("folderA" "folderX") for file in ./"${...
-2
votes
1answer
85 views

Move every 500 files in new directory [closed]

I have a directory that contains 10,665 jpeg files. I want to move 500 files to a new directory, and 500 to the next directory, etc. The largest files must be moved first: 500-1 contains the 500 ...
3
votes
1answer
140 views

What appropriate regex for recognizing a variable length file name?

I have a bash script that classifies and retrieves files from a remote server. I have trouble with the classification step, which is based on the file names. I am correctly able to identify the ...
-1
votes
1answer
35 views

bash: IF condition with keyworld within FOR loop

I am dealing with simple for loop, which loop the filles and execute on it some commands. I need to set up the filter with IF statement to consider only file started with the keyword "AllBoxes&...
4
votes
2answers
392 views

Bash script - variables in curly braces [duplicate]

The following bash script #!/bin/bash startNumber=$(( 1 )) endNumber=$(( $startNumber + 3 )) #for number in {$startNumber..$endNumber} for number in {1..4} do echo $number done exit 0 ...
1
vote
1answer
41 views

A variable inside an another variable

I have these variables a1=0.017 a2=0.2 a3=10.7 a4=20.9 a5=35.4 for ((x=1; x<=5; x++)) do for i in a${x} do echo "Welcome $i times" done done The output must be: "Welcome 0.017 ...
0
votes
0answers
16 views

Taking input from user as ~/directory_name and use the input as argument in different commands which require ~ to be expanded to $HOME? [duplicate]

I have written the following script which takes the path of the "download" directory from the user and then displays the filenames one by one using a for loop . Now someone may wonder why ...
0
votes
1answer
65 views

For loop to catenate files with two variables

I am relatively new to Linux in general and I hope someone can help me. I would like to merge fastq.gz files from 4 different sequencing lanes. Each file has the following name: GC082_F4.lane1.1901.R1....
0
votes
3answers
54 views

change filename based on current filename matched with separate file content

In one directory, I have several PNGs and one text file. The PNGs are named after UPC barcodes, like 052100029962.png, 052100045535.png, etc., and I have one text file upcs.txt where each line ...
0
votes
2answers
24 views

How to create a column that sums other columns using loops?

I want to create a new column in my file that sums the values of the 2nd and 3rd column for each line. For example I want 1 2 3 4 5 6 7 8 9 to give me 1 2 3 5 4 5 6 11 7 8 9 17 I've seen other ...
0
votes
0answers
23 views

Passing directory path as arguments and extract columns from files to make a new file with horizontal concatenation

I need a shell script which takes in the path of directories as arguments. The directory contains similar named files for eg. file1.dat, file2.dat etc. I need to take file1.dat from all the ...
1
vote
1answer
34 views

remote for loop with awk

I have a little program that gets the pids of 3 processes that are listening on different ports: Admins-Mac-mini-2:~ gitlabuser$ for pn in 23 33 43; do lsof -nP -iTCP:47${pn} | grep LISTEN | awk '{...
2
votes
2answers
59 views

changing IFS temporarily before a for loop [duplicate]

I know that the SHELL allows variable assignment to take place immediately before a command, such that IFS=":" read a b c d <<< "$here_string" works... What I was ...
0
votes
1answer
85 views

Move specific files to another folder based on partial pattern in .txt file

I have a folder with various file types, but I am interested in the files with .img as extension, with the following pattern: ppi_noTD_d0_P_76con_0001.img ppi_noTD_d0_P_104con_0001.img ...
3
votes
1answer
27 views

How to create a new file based on results from multiple files and keep the filenames as first column?

I wanted to extract specific lines from multiple bam (a binary file format) files. I can select the lines from a single bam file using this command: samtools view -c TCGA-BH-A0BW-11A.sorted.bam "...
0
votes
1answer
29 views

Rename and move files from one directory to another directory

Need your help on a command that run on a path1 to rename and move files from path2 to path3 Assume path1 = /data/run/ path2 = /data/output/ path3 = /data/archive/ path 2 contains few files like 'one....
2
votes
2answers
154 views

Return “continue” from function called from loop

I'm currently refactoring a script which has slowly grown beyond control. I'm trying to spin off repetition into functions. However, I have a repeated test being called from a loop, and want it to ...
0
votes
1answer
26 views

tar command in for loop starts from the wrong number

backup/ has the following files. ubuntu@ip-172-31-8-46:~/$ ls backup/ itrpl_dsm_10_1.tif itrpl_dsm_12_3.tif itrpl_dsm_2_3.tif itrpl_dsm_4_3.tif itrpl_dsm_6_3.tif itrpl_dsm_8_3.tif itrpl_dsm_10_2....
-1
votes
2answers
56 views

How do I get the required input for this 'for' loop?

I've written a small script made to backup downloads from TOR because occasionally TOR will try to merge its place holder file (a zero byte file with original file name) and its actual download file (...
5
votes
1answer
374 views

Adding suffix to filename during for loop in bash

This has probably been asked but the existing answers don't make sense to me. I am running a loop over multiple CSV files in a folder. This folder has non-csv files also and hence I must specify the ...
0
votes
1answer
50 views

finding the highest character length in each column using a loop and awk

I am trying to create a script that goes through a document and finds the highest character length in a column and return it. This script returns 78,78,78,78 when, what im aiming for is 10,11,14,51 ...
1
vote
1answer
59 views

appending values in a dynamic array

#!/bin/bash range=$(seq -f "cen%04g" 1052 1099) range1=$(seq -f "rh%04g" 1052 1099) check () { for node1 in ${range};do ping -q -c 1 -w 3 -s 10 $node1 >/dev/null if [ ...
0
votes
1answer
41 views

Bash array arent adding elements to last

root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# array=() root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# for i in 1 2 3 4 > do > array+=($i) > done root@kali-linux:~/Softwares/...
0
votes
1answer
14 views

Move files into sub-subfolders based on their file name, for multiple subfolders

I have 100+ subfolders (P_XXX), each containing three sets of files (run1, run2 and run3): /Analysis /P_076 /run1 /run2 /run3 swu_run1_P_076_vol_001.nii ...
0
votes
0answers
36 views

a shell “for” loop to get the list of vCPUs used in an openstack (RHEL) environment

I'm using RHEL 7.3 on OSP 10 I'm not great at scripting and mostly use sed/awk/for in single lines to get my outputs quick and dirty - but, I would like to be able to convert into an actual script as ...
0
votes
1answer
31 views

How can I place a column after another column for 1000 files?

I have 1000 odt files: file 1.odt with 6 columns (x,y,z,mx1,my1,mz1) file 2.odt with another 6 columns (x,y,z,mx2,my2,mz2) .... file 1000.odt with 5 columns (x,y,z,mx1000,my1000,mz1000) How can put ...
0
votes
3answers
42 views

What is the proper way to loop through each directory in a for loop? [duplicate]

For example, in this for loop for var in ????? do dummy command done I would like to be able to loop through each directory in the one that I am currently in, but it will be an unknown list of ...
0
votes
2answers
241 views

Fix Syntax error: unexpected end of file in a “for loop”

So I tried to fix this problem by myself for a couple of hours but I couldn't here's the code block that has a problem I changed it, rewritten, I even tried to "do" only echo after each line but it ...
0
votes
0answers
195 views

Using curl to create automatically the relative paths of the directories based on URLs hierarchy

I refer to my another question Using cURL, jq, and declaration and for loop condition, I tried to download multiple files from a GitLab private repo, but it downloaded only one. The question was ...
1
vote
1answer
323 views

Using cURL, jq, and declaration and for loop condition, I tried to download multiple files from a GitLab private repo, but it downloaded only one

I learned from the following sources: curl -O: Download a file with curl on Linux / Unix command line jq: How to urlencode data for curl command? Multiple files and curl -J: download pdf files from ...
3
votes
2answers
149 views

bash scripts with option flags inconsistent behavior

The code below is an mwe based on a script mwe I've written where I specify flags in what I think is the usual way. But I'm seeing really wierd behavior. If I type mwe -e or mwe -n it thinks ...
0
votes
0answers
25 views

dynamic variable name based on multiple for loop

I'm trying to create a dynamic name variables with the help of multiple for loop but the output says command not found. file marklist_theory.txt student1 10 student2 20 file marklist_practical.txt ...
0
votes
2answers
30 views

How do I copy a file within a subdirectory into an adjoining subdirectory?

My hierarchy is MyPDB -(5rea,5res,5rez) in which each 5rea, 5res, .. contain a directory called MD which contains a file named production_10ns.out. I want to copy production_10ns.out from each MD ...
1
vote
1answer
164 views

Using Grep to search a list and return matches

I have a short list of 1000 gene names and a full list of 20000 gene names with ID numbers. I have tried to set up a for loop to search for the shorter list in the full list to return the numbers. ...
-6
votes
2answers
37 views

For loop issue to get output

for a in {P02183606,P02183608,sassa} do for b in {PID,PID2,sas} do echo "http://indiafirstlife.com//onlineInsurance-rest/uploadDocument/uploadDocumentsOmniMannualPush?applicationRefNo=$...
1
vote
4answers
1k views

How to pass multiple variable to a for loop as a argument in a bash script? [closed]

I am new to linux and i am writing a bash script... In the script, I have 2 variables(inside the varibles contents are there). I am trying to pass these 2 varibales in a same for loop and perform some ...
0
votes
0answers
9 views

How to select from the output of a for loop (pipes)?

I'm essentially checking several databases using a query. sra-tblastn is a bioinformatics tool, but I don't think its specifics matter that much for the question at hand. The important part is that ...
2
votes
1answer
55 views

Bash for loop - can the commands in the loop be added to the shell's history?

On the bash terminal if I execute the following for loop: for i in {1..5}; do echo $i; done The echo commands are not added to the history of the current shell. Is it because the commands in for (...
0
votes
3answers
845 views

Renaming multiple files using a loop

I need to rename some files using a loop but I can't get it to work as I am still very new at Linux. the files that need to be renamed are: E9-GOWN33_multiplemap.bin.10.fa E9-GOWN33_multiplemap.bin....
0
votes
0answers
17 views

Create iCal VEVENT's from all values in array

So I've figured out how to parse the JSON data from a site to get the dates and times for when I'm scheduled to be at an event, and I've created a template to append to a .ics calendar file. The ...
0
votes
2answers
42 views

How to iteratively sum file sizes with given file extensions?

I'm stuck at figuring out how to sum ls 5th column result with awk. If I add $bytesum+=... then the program obviously breaks. Any ideas? bytesum=0 for i in `cat fileextensions.txt | sort | uniq` do ...
0
votes
2answers
157 views

using sed in a for in loop to remove words from file

I have a file 'book'(not txt) which contains text. I also have a list of words which I need to delete from said file. I have written this script but for some reason when I try to check and see if the ...

1
2 3 4 5
8