bash

echo newline suppression

Why $echo '-n' doesn't write -n on terminal although -n is written within quotes ? ...

How to pass parameters to a Linux Bash script?

I have a Linux bash script 'myshell'. I want it to read two dates as parameters, for example: myshell date1 date2. I am a Java programmer, but don't know how to write a script to get this done. The rest of the script is like this: sed "s/$date1/$date2/g" wlacd_stat.xml >tmp.xml mv tmp.xml wlacd_stat.xml ...

Remove a line from a csv file bash, sed, bash

I'm looking for a way to remove lines within multiple csv files, in bash using sed, awk or anything appropriate where the file ends in 0. So there are multiple csv files, their format is: EXAMPLEfoo,60,6 EXAMPLEbar,30,10 EXAMPLElong,60,0 EXAMPLEcon,120,6 EXAMPLEdev,60,0 EXAMPLErandom,30,6 So the file will be amended to: EXAMPLEfoo,...

Need help with shell script

I am a total newbie to Shell Scripting so please bear with me. I need to create a shell script called script1 that will calculate and then display letter grade of ABC2345. Read in the following grades from keyboard: Assignments 40% Test1 15% Test2 15% Final exam 30% Calculate and display the number grade using the weight of each fact...

Bash file descriptor leak

I get a file descriptor leak when running the following code: function get_fd_count() { local fds cd /proc/$$/fd; fds=( * ) # avoid a StackOverflow source colorizer bug echo "${#fds[@]}" } function fd_leak_func() { while : ; do echo ">> Current FDs: $(get_fd_count)" read r...

bash: how to know NUM option in grep -A -B "on the fly" ?

Hello everyone: I am trying to analyze my agent results from a collection of 20 txt files here. If you wonder about the background info, please go see my page, what I am doing here is just one step. Basically I would like to take only my agent's result out of the messy context, so I've got this command for a single file: cat run15.tx...

How do I redirect stdin/stdout when I have a sequence of commands in Bash?

I've currently got a Bash command being executed (via Python's subprocess.Popen) which is reading from stdin, doing something and outputing to stdout. Something along the lines of: pid = subprocess.Popen( ["-c", "cmd1 | cmd2"], stdin = subprocess.PIPE, stdout = subprocess.PIPE, ...

Embed bash in python

Hi, I am writting a python script and I am running out of time. I need to so some things that I know pretty well in bash, so I just wonder how can I embed some bash lines into a python script. Thanks ...

Calling Grep inside Java gives incorrect results while calling grep in shell gives correct results.

I've got a problem where calling grep from inside java gives incorrect results, as compared to the results from calling grep on the same file in the shell. My grep command (called both in Java and in bash. I escaped the slash in Java accordingly): /bin/grep -vP --regexp='^[0-9]+\t.*' /usr/local/apache-tomcat-6.0.18/work/Catalina/localh...

Parsing the first column of a csv file to a new file.

Operating System: OSX Method: From the command line, so using sed, cut, gawk, although preferably no installing modules. Essentially I am trying to take the first column of a csv file and parse it to a new file. Example input file EXAMPLEfoo,60,6 EXAMPLEbar,30,6 EXAMPLE1,60,3 EXAMPLE2,120,6 EXAMPLE3,60,6 EXAMPLE4,30,6 Desire output...

Loading variables from a text file into bash script.

Is it possible to load new lines from a text file to variables in bash? Text file looks like? EXAMPLEfoo EXAMPLEbar EXAMPLE1 EXAMPLE2 EXAMPLE3 EXAMPLE4 Variables become $1 = EXAMPLEfoo $2 = EXAMPLEbar ans so on? ...

Shell - Run additional command on failure

I have this script that I am currently running that works great for all instances but one: #!/bin/sh pdfopt test.pdf test.opt.pdf &>/dev/null pdf2swf test.opt.pdf test.swf [ "$?" -ne 0 ] && exit 2 More lines to execute follow the above code ... How would I go about changing this script to run "pdf2swf test.pdf test.swf" if "pdf2s...

How to make bash script ask for a password ?

I want to secure execution of a program with a password. How do i do that in bash ? Thank you ...

Bourne Shell: Graceful way to get exit status

Is there a more graceful way to do this (bourne shell)? IsThereAnyApplesLeft applesLeft=$? Normally in c or java I would do: applesLeft=IsThereAnyApplesLeft ...

Convert numbers to enumeration of strings in bash

Using bash, I have a list of strings that I want to use to replace an int. Here's an example: day1=Monday day2=Tuesday day3=Wednesday day4=Thursday day5=Friday day6=Saturday day7=Sunday If I have an int, $dow, to represent the day of the week, how do I print the actual string? I tried this: echo ${day`echo $dow`} but get error of...

Stop execution of python script when parent Bash shell script is killed

I'm working on a Bash shell script that runs several Python scripts like so: cd ${SCRIPT_PATH} python -u ${SCRIPT_NAME} ${SCRIPT_ARGS} >> $JOBLOG 2>&1 At one point, I killed the shell script (using kill PID), but the Python script continued running, even after the script terminated. I thought these would die as soon as the main script...

Calculating statistics directly from a CSV file

I have a transaction log file in CSV format that I want use to run statistics. The log has the following fields: date: Time/date stamp salesperson: The username of the person who closed the sale promo: sum total of items in the sale that were promotions. amount: grand total of the sale I'd like to get the following statistics: ...

bash shell date parsing, start with specifc date and loop through each day in month

Hi, I need to create a bash shell script starting with a day and then loop through each subsequent day formatting that output as %Y_%m_d I figure I can submit a start day and then another param for the number of days. My issue/question is how to set a DATE (that is not now) and then add a day. so my input would be 2010_04_01 6 my out...

Bash script to pull out x number of starting comment lines into another file

I am looking for a one liner to pull out the first comment block in any file. The comment blocks look like this: /* * This is a * comment block */ I've been trying to play with sed, but just can't get it to work right. Help? ...

bash tips needed for understanding how to escape characters in command-line

My knowledge of commandline bash is missing on a particular area: I constantly forget how to properly escape characters. Today I wanted to echo this string into a file: #!/bin/env bash python -m SimpleHTTPServer echo "#!/bin/env bash\npython -m SimpleHTTPServer" > server.sh && chmod +x server.sh -bash: !/bin/env: event not found That...