The tag has no usage guidance.

learn more… | top users | synonyms

1
vote
3answers
41 views

how can we use multiple variables in single for loop in shell script?

I am implementing as below code using for loop but wrong output coming after running the script. for i in `awk -F"|" '{print $1}' $INPUTFILE`, j in `awk -F"|" '{print $2}' $INPUTFILE` do echo $i:$j ...
-1
votes
1answer
34 views

for loop to evaluate multiple directories and execute command

I was editing a shell script and I want to know how can use for to use all directories listed by a list or variables and then execute a command. Example: I have this directories: /dirname1/app1 ...
0
votes
1answer
40 views

Loops: for vs while… beyond the basics. Subtle differences/pros/cons for my code? [closed]

I have been writing/refining a relatively complex code for the past year, and learning bash along the way. My code is filled with functions that have complex multi-level while loops. I've recently ...
1
vote
1answer
47 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ...
3
votes
2answers
46 views

Iterating over glob patterns, not the files in them

I would like to perform the same aggregation operations on each of several bunches of files where each bunch is matched by one glob pattern. What I would not like to do is pipe each file name into the ...
1
vote
0answers
39 views

Assigning floating point value to array in Unix shell script loop [closed]

I am using ksh scripting on Ubuntu 14.04 and am trying to write a script to add floating point numbers to an array. My code is as follows numLoops=6 numerator=14996288 denominator=1000000000 for i ...
1
vote
2answers
76 views

How do I use a temporary environment variable in a bash for loop?

I want to run YII_ENV=prod yii kw/test ten times. I tried $ YII_ENV=prod for x in 1..10 do; yii kw/test done; -bash: for: command not found 1304682651 (Seemed to run once.) I also tried $ for x in ...
1
vote
1answer
17 views

Create subdirectories under a parent but prompt for the name of the parent

I use SCP a lot to transfer log files from servers to a jumpbox where I can analyse and troubleshoot etc. If I have a cluster of servers and I want to create a set of subdirectories I do it like this: ...
6
votes
2answers
162 views

for loop over input lines

I have a file with a lot of lines like this /item/pubDate=Sun, 23 Feb 2014 00:55:04 +010 If I execute this echo "/item/pubDate=Sun, 23 Feb 2014 00:55:04 +010" | grep -Po "(?<=\=).*" Sun, 23 ...
0
votes
0answers
15 views

Loop through directory and sum value next to specific pattern producing an average

I want to loop through all the files in the directory. the files are set out like this: <Overall>4 other data <Overall>2 other data ...... I have the code: for file in .dat; do awk ...
0
votes
1answer
29 views

regex to remove last four characters

Is there a way I could eliminate the last four characters with regex in the below one line script as I convert .wav files into .mp3 files. As of right now my single line script produces files ending ...
-6
votes
1answer
38 views

I am facing hoping issue in my script, please help me [closed]

for i in `ls -ltr | grep ' Nov' | awk '{print $NF}'` do for j in `unzip -l $i | grep -i SystemOut | awk '{print $NF}'` do unzip -c $i | grep -i Live | grep 'smarter planet' done ...
3
votes
4answers
359 views

How do you create a for loop with a changeable number of iterations?

How do you iterate through a loop n amount of times when n is specified by the user at the beginning? I have written a shell script and need to repeat a certain part of it n numbers of times ...
0
votes
1answer
31 views

Skip for loop iteration depending on response to inner select

I have the following bash script, which iterates through all the images in a directory and attempts to determine the date and time it was created using exif. If the exif information is not available, ...
-1
votes
2answers
60 views

bash shell script two variables in for loop

for SLAVE_CLUSTER,MASTER_CLUSTER in $MASTER_CLUSTERS $SLAVE_CLUSTERS do echo "Master cluster boxes are ${!MASTER_CLUSTER}" echo "Slave cluster boxes are ${!SLAVE_CLUSTER}" done I am ...
-1
votes
2answers
47 views

Script with nested for loops [closed]

This is the code and I need to display in the terminal like this way: (1,1) (1,2) (1,3) (1,4) (1,5) (2,1) (2,2) (2,3) (2,4) (2,5) (3,1) (3,2) (3,3) (3,4) (3,5) (4,1) (4,2) (4,3) (4,4) (4,5) but ...
0
votes
2answers
87 views

for loop in bash

I want to create a for loop that runs from 1 to a number stored in a variable. But it produces this error: Syntax error: Bad for loop variable This is my script: #!/bin/bash count_lines () { ...
0
votes
0answers
68 views

Make whiptail work in a for loop

This is my first question ever here... So please be gentle :) I have a bash script that checks ping for 163 sites(stores around the country), which is this: #!/bin/bash #storestest.sh #version 0.9.2 ...
0
votes
1answer
76 views

Bash For Loop - prompt for IP range and password

I have a simple for loop one liner I use to check for things across a number of servers that have the same password set. I want to develop this one liner into a script that logs into a cluster of ...
1
vote
1answer
19 views

How do I write a script to automatically compile and install all Moksha modules?

I have this repository cloned on my Sabayon machine, what I would like to do is write a script that will change into each directory of this repo (just the top-level directories, not directories inside ...
2
votes
2answers
331 views

How do I get ~/.bashrc to execute all scripts in my ~/Shell directory using a loop?

I have shell scripts in my ~/Shell directory that I want to be run whenever Bash is started up as my usual user account. So what I have done is added the following to ~/.bashrc: for i in `find ...
3
votes
1answer
52 views

Shell script - Couldn't find 'fi' for this 'if'

I have found this error alongside couple more. I believe that the nesting is not quite all right or the for is not correctly indented or without some semicolon. Either way I have tried for quite some ...
1
vote
2answers
105 views

Efficient way to search array in text file by AWK

I have one array SPLNO with approx 10k numbers.Now i want to search the subscriber number from MDN.TXT file (containing approx 1.5 lac record)from the array.if subscriber number found in array it will ...
-2
votes
1answer
29 views

help me with create shell script with bash scripting [closed]

I want to make the script to extract the users of linux server and check if "/home/$user/public_html/vb/includes/config.php" is exist , i want the script to check all the users in the server and ...
0
votes
0answers
14 views

How to copy files which includes spaces [duplicate]

I have the code below: for i in *.pdf; do mv $i books/; done This line of code selects file by words not the whole file name, so when it tries to move "The code of valamor.pdf" it gives the output ...
1
vote
0answers
33 views

Cannot terminate for loop in terminal

I was running a for loop in terminal which has a sox command in it. For some reason the sox command failed and now I cannot terminate the for loop. I tried pressing Ctrl+c many times, Ctrl+z many ...
1
vote
0answers
118 views

csh: redirecting output from foreach

In csh: How do I redirect the output from a foreach-loop to a pipe? This works but uses a temp file: set tmpfile=/tmp/file ...
1
vote
2answers
36 views

extract part of the text from all matching lines

I am running a for loop against set of servers to find the cert expiry. Output of the cert command will be below for each server: line 1 line 2 line 3 Valid From: Tuesday, 29 September 2015 10:40:13 ...
1
vote
2answers
112 views

SSH to servers with sudo access - script throws unexpected end of file error

I've to run a command iptables --flush in 100+ servers. I don't have root credentials, but have sudo access for my account. So I come up with a below script to run the command in all servers. I added ...
-2
votes
1answer
59 views

Find part of filename

Please help with my task: I have a folder with three sub-folders containing six files each. There are two files in each sub-folder with :nopm in their file names. I need to create a shell script ...
0
votes
0answers
74 views

Directory research example

I have a folder with three sub-folders containing six files each. There are two files in each sub-folder with :nopm in their file names. I need to create a shell script that checks all the folders ...
2
votes
1answer
29 views

Copying directories unrelated file names

Apologies for the dumb question. I'm trying to copy directories of data sets that pertain to the a certain case but the data sets are currently stored in different directories and with different (non ...
1
vote
2answers
65 views

Help understanding bash script

I'm a bit stuck trying to understand the following script from a book: values=(39 5 36 12 9 3 2 30 4 18 22 1 28 25) numvalues=${#values[@]} for (( i=0; i < numvalues; i++ )); do lowest=$i ...
3
votes
4answers
235 views

Help with bash script

I am teaching myself bash scripting with the book 'Learning the Bash Shell' by Newbam. I'm getting on OK with the book, but am a bit confused by the following script. It is a script which uses a for ...
8
votes
4answers
1k views

bash loop with 0.02 increment

I want to make a for loop in bash with 0.02 as increments I tried for ((i=4.00;i<5.42;i+=0.02)) do commands done but it didn't work. I appreciate if you help me out.
0
votes
1answer
234 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command sets from a file and then execute each over a set of files. The prepared file should serve as a template for execution in manual ...
6
votes
2answers
9k views

In a loop over an array, add an element to the array

I have a problem with for loop in bash. For example: I have an array ("etc" "bin" "var"). And I iterate on this array. But in the loop I would like append some value to the array. E.g. array=("etc" ...
0
votes
2answers
38 views

Script to find logs in directory

I have my loop for: for i in 1.34* do if [ -f $i/rela/*log ] ; then echo $i >> /tmp/allog else echo $i >> /tmp/alnolog fi done Is working well. We have different version of releases ...
2
votes
1answer
757 views

For Loop for Google Image Downloading Bash Script

I have a bash script which downloads images from Google Images. This is the command I use: bash getimages.sh 3 rocky%20mountains That command will download the 3rd picture in Google Images. To ...
0
votes
1answer
41 views

How to grouped the following variable and command and read 1 by 1

I've following array and variable : httpurl="http://www.nnin.com" firstquery=$(curl -s -X POST -d "UID=user1&PWD=1111" $httpurl) name="firstcust" ip="105.105.0.1" httpurl="http://www.mmim.com" ...
0
votes
2answers
93 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
68 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
93 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
1k 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 ...
6
votes
4answers
550 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
114 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
94 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
2answers
304 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
177 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
112 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 ...