The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
2answers
26 views

Variable in for loop to be used as an array for a csv output

I've been struggling to come up with a solution for this, the goal is to organize the results into comma separated columns as we have to recable our entire datacenter from cat6 to cat6a. $DBFILE ...
2
votes
3answers
53 views

Bash | port killing loop fails

I am trying to create a bash function which should kill all processes using some ports specified in port_array. The kill-port function works if I call it myself with a port e.g. with kill-port "80";. ...
0
votes
2answers
65 views

How to use 3rd variable in BASH for loop?

Good day. I want to parse data of particular columns from several files(aprilPlate.txt, mayPlate.txt, junePlate.txt, julyPlate.txt, augustPlate.txt) using For loop. The data of input files ...
0
votes
4answers
85 views

Foreach loop for ls output

I am trying to process some files in directory using foreach loop for ls output: IFS=$'\n' for i in $(ls -1Atu); do echo "$i" done At first time i thought it works, but when i created file ...
5
votes
4answers
257 views

Converting `for file in` to `find` so that my script can apply recursively

I've been working on my first bash script for some time now (I just started UNIX this week). I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the ...
1
vote
1answer
45 views

using `for file in` to select multiple extension names then get the basename of “file” then concatenate an extension name

I am trying to practice my unix skills, I just learned how to use for file in *.jpg; what it does is select all files with .jpg in the working directory, but I do not want to stop there and I do not ...
3
votes
2answers
80 views

using the variable “file” obtained from `for “file” in` and pass to another script fails [closed]

I am trying search for all .mkv files in my current folder, then using mediainfo I want to put the height from its meta data to a variable, but it seems it is failing. This snippet: ...
4
votes
1answer
78 views

uniq and bash for loop not writing to stdout before stdin closing (for one-line website visitor notification system)

I'm trying to trigger a beep on the PC speaker for every unique visitor of a website. After some brainstorming, it seemed to be possible with one line: for e in `ssh me@mymachine "tail -n 1 -f ...
3
votes
2answers
46 views

get timestamp of files presented by FOR loop

My aim is to find $files on some $devices and save them to one or more folders which are namend corresponding to a timestamp of each file. To get the timestamp I wanted to use stat. In contrast to ...
0
votes
1answer
36 views

Use sed as argument for basename

I have this code so far... for i in {1..200}; do sed '$i,0!d' md5list.txt | grep -a ": "; done I would like to run basename for each iteration of the code above, like so: basename $(for i in ...
1
vote
1answer
45 views

BASH: looping through ls [duplicate]

I'm having trouble with this piece of code: 22 for filename in "$( ls "$1" | grep ".*\.flac$" )"; do 23 file_path="$1${filename}" 24 ffmpeg -i "${file_path}" -f ...
1
vote
2answers
159 views

Creating multiple input files by using sed in a for loop

I am a newbie and wasted a lot of time on this so any help is greatly appreciated. Suppose I have a simple Mathematica script file named "a.m" which contains the parameter 'a' with no assigned value: ...
1
vote
1answer
43 views

How to replace string of the file, which is present in tar file through UNIX

I have a tar archive xyz.tar containing lots of .sh files like: 123.sh 456.sh 789.sh Every .sh file has some string content, e.g. 123.sh contains welcome to Hollywood, 456.sh contains I love ...
0
votes
1answer
31 views

Values from two lists are not processing correctly within two nested loops

I am trying to pass some values contained in two lists to a simple echo within two nested for loops (the echo is used to look at what is generated inside the inner loop). But the results are not ...
1
vote
3answers
58 views

for loop over a list

I have a small script which should print a couple of calls to a makefile i got. mylist='$(call list_samples,AON_9,NT_1,SC_17) $(call list_samples,AON_10,NT_2,SC_18) $(call ...
3
votes
3answers
90 views

Write bash function which operates on list of filenames

I want to define the function cpfromserver in bash so that when I run $ cpfromserver xxx yyy zzz the result is the same as if I had typed $ scp user@remote.server:"/some/location/xxx/xxx.txt ...
3
votes
1answer
36 views

Get git branch from several folders/repos

I have a folder with several repositories inside. Is there any way I can run git branch or whatever git command inside each folder? $ ls project1 project2 project3 ...
0
votes
1answer
81 views

For loop brackets - C like syntax

When i am using the below syntax to iterate why two brackets are needed ? for (( expr1; expr2; expr3 )) do command1 command2 .. done and the below code doesn't work ? and throws error "syntax ...
0
votes
2answers
65 views

for loop not working for multiple lines

I have a array like this "Apple Banana Clementine Date" I have to print like this: 1. Apple 2. Banana 3. Clementine 4. Date Script file: for i in "${fruits[@]}"; do echo "$lineno. $i " ...
1
vote
3answers
197 views

for loop for running a command for all files in a folder

Suppose I have a folder which contains a lot of audio files. How can I write a for loop so that for each file audioname.mp3 in the folder, these commads are run: convert -size 300x200 xc:lightblue ...
3
votes
4answers
244 views

what is the difference between `find .` and /home/user/* as an input to for command

What is the difference between find . and /home/user/* as an input to for command.? For example: for var in $(find .) do echo "$var" done or for var in /home/user/* do echo "$var" done In the ...
2
votes
2answers
88 views

for loop to iterate through some file nth position

How do I iterate for nth file in a for loop in unix? below some code I have tried but not succeeded #!/bin/bash # n=2 array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" ) ...
3
votes
2answers
93 views

How do I perform the same set of commands within multiple subdirectories, in a numerical order?

Within my parent_directory, I have subdirectories labeled E-11_G, and E-10_G. Within each of those subdirectories, I have more subdirectories labeled E-2_U, E-1_U, and E0_U. In each of those folders, ...
1
vote
2answers
262 views

Parse two files input in for/while loop

I have two files with two different values. I want to run a command in loop which needs input from both file. Let me give the example to make it simple. File1 contents: google yahoo File2 ...
1
vote
0answers
99 views

passing variable through cat EOF command with for loop

How do I get the script run with the sbatch command to run with the 23 individual run_prep_chem_$dd.sh (i.e. run_prep_chem_08.sh...run_prep_chem_30.sh)? I am thinking since its in this for loop that ...
0
votes
1answer
161 views

reading file using for, while - behavior

Consider the below scenario 2 vms - 192.168.229.131, 192.168.229.132 Both the vms has it's ip as 192.168.229.151 & 192.168.229.152 in it's /etc/hosts file Say there are around 50 vms like i ...
0
votes
2answers
465 views

proper way to iterate through contents in a directory [duplicate]

I need to iterate through every file inside a directory. One common way I saw was using the for loop that begins with for file in *; do. However, I realized that it does not include hidden files ...
0
votes
2answers
78 views

Find and for loop

Trying to do a mass convert from M4A to OGG in a large music collection, I have: #!/bin/sh for i in `find /home/family/Music -name *.m4a -print0` #do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac ...
3
votes
2answers
152 views

Loop in WildCard as Input of Script

I want to use my script on many files sometimes. I used this for the purpose: for etminput in $1 do #process done But this just gives the first input. How can I do the process on every ...
1
vote
2answers
80 views

awk: for-loop with break option

I am trying to use awk to manipulate data.I have a data file with two columns and I would like to find the row that contains an specific value. But there is more than one row that contains this value ...
1
vote
1answer
46 views

accessing substrings from lines in a text file and storing them

I have a text file like this chr1:16840617-16840780 RNU1-1 (2 columns are tab separated) chr3:142139047-142139211 RNU1-100P ............ ............ I want to loop over the lines ...
2
votes
1answer
65 views

reset for loop counter

Simple question: if I have a for loop (zsh) over an unreliable list, by which I mean the list contains entries that can't be predicted beforehand, then can I reset the for loop counter? This ...
2
votes
1answer
3k views

Attach files for sending mail which are the result set of find command

By using find command I got multiple files. Now I want to add all these files as mail attachment. Please help me how to add these files as attachment in single mail. I want to implement this in ...
3
votes
1answer
332 views

Why does this command to copy files in a for loop work in bash but not in zsh?

I'm trying to copy a bunch of files with the same name, but in different subdirectories, to a single directory, changing the names to ones based on the paths to the original files. I use a for loop ...
3
votes
6answers
2k views

Remove last comma from a bash for loop generated string

I am dealing with a situation where I need to create a comma separated list from an array into a heredoc and remove the last comma. I am using bash for piped into sed which is erasing all commas ...
5
votes
3answers
5k views

For loop in Unix : including files from sub directories [duplicate]

A simple for loop in Unix would be: for FILE in $BASE_WORK_DIR/*.pdf do echo $FILE done This will echo all .pdf files inside BASE_WORK_DIR directory. What if BASE_WORK_DIR contains sub ...
4
votes
4answers
358 views

Continue for loop by keyboard

I have user account on a linux machine which I do not know its exact IP address. But I know a range which it is ran on one of them. I want to check which server is my desired server. There are some ...
0
votes
1answer
159 views

I need Control loop help -

this is what I figured out in sorting an Array that has already had it's elements declared type int #!/bin/bash #sorting an "predeclared" array typeset -i store BigNum let store=0 BigNum=0 ...
3
votes
4answers
311 views

Bash: For loop with binary range keeping control value binary

Let's say I have two bash variables that contain binary values: a=0011 # decimal 3 b=1000 # decimal 8 Is there a way I can loop through all the possible values between $a and $b keeping it binary? ...
1
vote
1answer
47 views

for + array + args

I have problem with my for cycle, this is what I want: for arg do array[index]=(`find $arg -type l -maxdepth $depth -printf "%p\n" `) index++ done fi arg - positional arguments, only directories ...
1
vote
3answers
67 views

return the numeric value of a indexed variable rather than its name [duplicate]

The following piece of code illustrates my problem I'm afraid I oversimplified it way too much in the first round. #!/bin/bash dogLover=1 catLover=2 for ii in dog cat do ...
2
votes
2answers
966 views

Using for loop to brute-force a password

I just wanted to brute-force my old router but the for-loop was really amateur style. How to write a nice for-loop, if I only know the charaters included? Found already that page but it does not ...
2
votes
3answers
770 views

Command substitution in for loop not working

I want to keep all files not ending with .bat I tried for f in $(ls | egrep -v .bat); do echo $f; done and for f in $(eval ls | egrep -v .bat); do echo $f; done But both approaches yield the ...
1
vote
6answers
16k views

bash variables in for loop range [duplicate]

I want to print list of numbers from 1 to 100 and I use a for loop like the following: number=100 for num in {1..$number} do echo $num done When I execute the command it only prints {1..100} and ...
5
votes
3answers
788 views

Walking through files in directory randomly

How to change for track in *.mp3; do so that all .mp3 files in the current directory are walked through but in a random way?
2
votes
2answers
245 views

Why won't the for loop execute on directory

In the following script, the first for loop executes as expected, but not the second. I do not get any error, it seems that the script just hangs. HOME=/root/mydir DIR=$HOME/var DIRWORK=$HOME/Local ...
4
votes
5answers
7k views

Piping output to text file within a for loop

I'm trying to do the following within a for loop: Find files that satisfy a condition Echo the name of the files to a log file. Gzip the file. I can get the script to find the files and echo their ...
4
votes
3answers
373 views

${!FOO} and zsh

${!FOO} performs a double substitution in bash, meaning it takes the (string) value of FOO and uses it as a variable name. zsh doesn’t support this feature. Is there a way to make this work the same ...
2
votes
1answer
2k views

Why the behavior of while loop and for loop is different?

I am trying to read user and server details from file tempo.txt and then check the disk space usage of the file system on that unix account using another script server_disk_space.sh.But I am not able ...
10
votes
4answers
1k views

Avoiding errors due to unexpanded asterisk

In bash I often use for-loops such as the following for file in *.type; do sommecommand "$file"; done; to perform an operation for all files matching *.type. If no file with this ending is ...