for-loop

Array Values from Text or CSV File in Shell

Deadly 提交于 2020-01-16 08:03:31
问题 I am having a script in which I am declaring arrays like below: declare -a Pool=("Terrace|HouseTerrace_") declare -a Library=("lib1 lib2 lib3") declare -a Name=("Guru/Raju Albert Deepak") declare -a Email=("Guru@american.com,Raju@american.com Albert@american.com Deepak@amaerican.com") Sub=("Media Rotation") i=0 while [ $i -lt ${#Pool[@]} ] do command blah balh blah i=`expr $i + 1` done Now what i want is that instead of declaring values in aaray here i should import it from file (either text

Array Values from Text or CSV File in Shell

六眼飞鱼酱① 提交于 2020-01-16 08:03:06
问题 I am having a script in which I am declaring arrays like below: declare -a Pool=("Terrace|HouseTerrace_") declare -a Library=("lib1 lib2 lib3") declare -a Name=("Guru/Raju Albert Deepak") declare -a Email=("Guru@american.com,Raju@american.com Albert@american.com Deepak@amaerican.com") Sub=("Media Rotation") i=0 while [ $i -lt ${#Pool[@]} ] do command blah balh blah i=`expr $i + 1` done Now what i want is that instead of declaring values in aaray here i should import it from file (either text

For loop within for loop with OR

大憨熊 提交于 2020-01-16 05:26:05
问题 I'm a bit stuck. I want to return my posts and my followed_users posts. I have a association called "followed_users" so I am able to call @user.followed_users <% for friends in current_user.followed_users %> <% for post in friends.posts %> <%= post.body %> <% end %> <% end %> This works, however only for "followed_users" posts. I also want to include my posts. So my plan is first check for my post then loop through all to see which belongs to my followed_users. My implementation is returning

Reading a text file then performing a character count and printing the relative frequency of each one

放肆的年华 提交于 2020-01-16 05:13:07
问题 I'm looking to perform a character count on a text file and then display each one with it's relative frequency to the rest of the characters, but I'm presently getting just blank console back. Any help would be greatly appreciated. import java.io.*; public class RelativeFrequency { public static void main(String[] args) throws IOException { File file1 = new File("Rf.txt"); BufferedReader in = new BufferedReader (new FileReader (file1)); System.out.println("Letter Frequency"); int nextChar;

second command in a batch for loop

て烟熏妆下的殇ゞ 提交于 2020-01-16 04:52:06
问题 I want to write a code in batch like the following: for %%a in (%list%) do ( command1 command2 command3 command4 . . . ) The first command for the first element of the list is executed correctly. But in command2 there are errors. In the cmd-window I can see what happend. And in the command isn't changed the %%a to the value. There is a "%a" instead of the value. In my code there is "%%a" exactly like in command1. What is the mistake here? How can I execute more than one command in a batch-for

Performance loop with integer vs Long index

时光总嘲笑我的痴心妄想 提交于 2020-01-16 04:13:47
问题 I am wondering why it takes so much longer to run a loop with a long index vs. an integer index? Any idea? Thanks int n = 1000_000_000; long n2 =n; long t1 = System.currentTimeMillis(); for( int idx = 0; idx<n;idx++){ } long t2 = System.currentTimeMillis(); for( long idx = 0; idx<n2;idx++){ } long t3 = System.currentTimeMillis(); long dt1 = t2-t1; long dt2 = t3-t2; System.out.println("with int = took " + dt1 +"ms"); System.out.println("with long = took " + dt2 +"ms"); 回答1: It possible has

.BAT file to loop through numbers - Need to add 0 to numbers less than 10

有些话、适合烂在心里 提交于 2020-01-16 04:09:14
问题 I have a number of .bat files that are opening a program and finding a specific instance that is ran everyday. This instance is timestamped and changes everyday. So I am having the .bat file run through everynumber looking for that instance. The format is YYYYMMDDHHMMSS. From this site I already have a .bat file that finds the previous business day. I even have it looping through the numbers The problem is if the number is less than 10, it needs to have a 0 in front of it: 01,02,03,04 etc...

ListView Changes Data on Scroll

痴心易碎 提交于 2020-01-16 01:09:12
问题 I have a ListView that is correctly populated with an array on create, but when I scroll, the data changes and is all out of order. I don't know wether the problem is in my CustomListViewAdapter or in my DetailsPage. Here's the For Loop that I am using to generate the textViews : if (currentObject.setTime != null && currentObject.setName != null) { String[] temporaryNames = currentObject.setName; int totalNames = (currentObject.setTime.length / currentObject.setName.length); for (int i = 1; i

c++ loop macros

為{幸葍}努か 提交于 2020-01-16 01:07:35
问题 I use macros to code unrolled loops like this: (silly example) #define foreach_small_prime(p, instr) { \ int p; \ p = 2; instr; \ p = 3; instr; \ p = 5; instr; \ p = 7; instr; \ } foreach_small_prime(pp, cout << pp); int sum = 0; foreach_small_prime(pp, { sum += pp; if (sum >= 10) cout << sum << endl; }); But in some cases I might use for construct: #define foreach_small_even(ii) for(int ii = 0; ii < 20; ii += 2) int sum = 0; foreach_small_even(pp) { sum += pp; if (sum >= 10) cout << sum <<

Is this a bug in windows batch?

南笙酒味 提交于 2020-01-16 00:56:11
问题 I have found a peculiar issue with batch scripting that I cannot seem to explain. Maybe its just because I do not know enough about the underpinnings of how batch works but here is an example batch file (test.bat): @echo off FOR /F "tokens=1*" %%i in ("%*") DO ( echo %%j ) if I call it like so: test.bat ab a,b "a,b" I get this as my output: a,b "a b" Why was the second comma stripped out? If I escape the comma like so: test.bat ab a,b "a^,b" I get the correct output: a,b "a,b" It is almost