Hi all -
I would like to make a section of my code more efficient. I'm thinking of making it fork off into multiple processes and have them execute 50/100 times at once, instead of just once.
For example (pseudo):
for line in file;
do
foo;
foo2;
foo3;
done
I would like this for loop to run multiple times. I know this can be done w...
How can I comment on each line of the following lines from a script:
cat ${MYSQLDUMP} | \
sed '1d' | \
tr ",;" "\n" | \
sed -e 's/[asbi]:[0-9]*[:]*//g' -e '/^[{}]/d' -e 's/""//g' -e '/^"{/d' | \
sed -n -e '/^"/p' -e '/^print_value$/,/^option_id$/p' | \
sed -e '/^option_id/d' -e '/^print_value/d' -e 's/^"\(.*\)"$/\1/' |...
I realize I could do this in any other language - but with Bash - I've looked far and wide and could not find the answer.
I need to manually increase $line in a script:
Example:
for line in `cat file`
do
foo()
foo_loop(condition)
{
do_something_to_line($line)
}
done
If you notice, every time the foo_loop iterates, $line stay...
I have a text file like this:
Apple
Orange
Orange
Banana
Banana
Orange
Banana
Orange
Apple
Orange
I want to produce the following output after running a bash shell script:
Apple: 2
Orange: 5
Banana: 3
It's pretty standard stuff if I use a full blown language like Java/C++ etc but what is the quickest way to do it with a shell scrip...
I'm writing a Bash script in which I am running a perl script which requires flags that have double quotes in them. Running the script normally, you would run
$ perl script.pl -flag="something" -anotherflag="somethingelse"
In my script, I'm using variables in these flags, but would like to preserve the doublequotes, so I have somethin...
Hello everyone. I got a document that fields are separated by a colon(:) where I need to change the second field from time to time. The document looks like this:
name1:UhX.PPFW7$YhPMH0BISY:23490::::::
name2:1./0oV$GEs6WJpE$LHXhy:19239:0:29388:2::29302:
...
The second field of the file will change occasionally and may contain a coupl...
Hello!
I bumped into the following problem: I'm writing a Linux batch script which does the following:
Read line from file
Strip the \n character from the end of the line just read
Execute the command that's in there
Example:
commands.txt
ls
ls -l
ls -ltra
ps as
The execution of the batch file should get the first line, and execu...
I want to print
userId = 1234
userid = 12345
timestamp = 88888888
js = abc
from my data
messssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
<input name="userId" value="1234" type="hidden"> messsssssssssssssssssss
<input name="userid" value="12345" type="hidden"> messssssssssssssssssss
<input name="timestamp" valu...
I'm attempting to emulate the functionality of the bash shell script below using a Process or ProcessBuilder object in Java. It's not 100% clear to me how I do the redirection for standard-in. How can I accomplish this?
#
# Redirect shell echo command from standard output to file
# This will construct the input file
#
exec 1> $STDIN
...
I need to understand the following line of code:
BIN_DIR=`grep BIN_DIR= $SMLCM | head -1`
where $SMLCH contains a path
This is what I understood so far:
grep will produce some string(s), possible paths. What does grep do with BIN_DIR=?
the pathes are passed to head and all files within the paths will be used to extract their first ...
Suppose you want to make a bash script which supports no options but acts like cp, because the cp supplied by your system does not accept multiple sources.
The usage for the system's (hypothetical and broken) cp is:
cp source target # target may be a directory
The usage for the script will be:
cp.sh source... target # target m...
There's a similar post @ http://stackoverflow.com/questions/5071/how-to-add-cvs-directories-recursively
However, trying out some of the answers such as:
find . -type f -print0| xargs -0 cvs add
Gave:
cvs add: cannot open CVS/Entries for
reading: No such file or directory cvs
[add aborted]: no repository
And
find . \! -name...
Why did it take 5 minutes to generate a 1 KiB file on my (low-end laptop) system with little load? And how could I generate a random binary file faster?
$ time dd if=/dev/random of=random-file bs=1 count=1024
1024+0 records in
1024+0 records out
1024 bytes (1.0 kB) copied, 303.266 s, 0.0 kB/s
real 5m3.282s
user 0m0.000s
sys 0m0....
I have been trying for about an hour now to find an elegant solution to this problem. My goal is basically to write a bandwidth control pipe command which I could re-use in various situations (not just for network transfers, I know about scp -l 1234). What I would like to do is:
Delay for X seconds.
Read Y amount (or less than Y if the...
I wanted to know why i am seeing a different behaviour in the background process in Bash shell
Case 1: Logged in to Unix server using Putty(SSH)
By default it uses csh shell
I changed to bash shell
typed sleep 2000 &
press enter
It gave me the job number. Now i killed my session by clicking the x in the putty window
Now open anothe...
How to set a global environment variable in a bash script?
If I do stuff like
#!/bin/bash
FOO=bar
...or
#!/bin/bash
export FOO=bar
...the vars seem to stay in the local context, whereas I'd like to keep using them after the script has finished executing.
...
I have created a little password generation script. I'm curious to what improvements can be made for it except input error handling, usage information etc. It's the core functionality I'm interested in seeing improvements upon.
This is what it does (and what I like it to do):
Keep it easy to change which Lowercase characters (L), Uppe...
I am running a jar file from within an app bundle on Mac OS X Leopard. I need to pass into the jar a parameter. The parameter is the absolute path of the file which called the app bundle. I have my short bash script below. I know $0 gives the absolute path to the app bundle itself.
Does anyone know how to store in a variable the path I...
I have some SQL scripts that I'm trying to automate. In the past I have used SQL*Plus, and called the sqlplus binary manually, from a bash script.
However, I'm trying to figure out if there's a way to connect to the DB, and call the script from inside of the bash script... so that I can insert date and make the queries run relative to a...
I have a string, like a sentence, and I know for sure that there are many words with at least one space separate every adjacent two. How can I split the words into individual strings so I can loop through them?
EDIT:
Bash
The string is passed in as an argument. e.g. ${2} might be "cat '' cat '' file". so how can I loop through this ar...