bash

Split line into words in bash

Hi, I realize how to do it in python, just with line = db_file.readline() ll=string.split(line) but how can I do the same in bash? is it really possible to do it in a so simple way? Thanks ...

grep 5 seconds of input from the serial port inside a shell-script

I've got a device that I'm operating next to my PC and as it runs it's spitting log lines out it's serial port. I have this wired to my PC and I can see the log lines fine if I'm using either minicom or something like: ttylog -b 115200 -d /dev/ttyS0 I want to write 5 seconds of the device serial output to a temp file (or assign it to ...

Split a database of mol2 molecules into N smaller sets

Hi, I got a big set of molecules from the zinc database (http://zinc.docking.org/), in mol2 (http://tripos.com/index.php?family=modules,SimplePage,,,&page=sup_mol2&s=0) format. I would like to be able to split this database into an arbitrary set of N smaller databases. What is the best scripting approach in either python, bash o...

Passing a string with spaces as a function argument in bash

I'm writing a bash script where I need to pass a string containing spaces to a function in my bash script. For example: #!/bin/bash myFunction { echo $1 echo $2 echo $3 } myFunction "firstString" "second string with spaces" "thirdString" When run, the output I'd expect is: firstString second string with spaces thirdStr...

How to cut some text from string in bash?

Bash script I have a string: tcp 6 0 CLOSE src=111.11.111.111 dst=222.22.222.22 sport=45478 dport=5000 packets=7 bytes=474 src=111.11.111.111 dst=222.22.222.22 s port=5000 dport=45478 packets=8 bytes=550 [ASSURED] mark=0 use=1 I need cut src IP addr 111.11.111.111, how? ...

Bash combine two arrays

I have the following situation, two arrays, let's call them A( 0 1 ) and B ( 1 2 ), i need to combine them in a new array C ( 0:1 0:2 1:1 1:2 ), the latest bit i've come up with is this loop: for ((z = 0; z <= ${#A[@]}; z++)) do for ((y = 0; y <= ${#B[@]}; y++)) do C[$y + $z]="$...

Bash: redirect standard input dynamically in a script

I was trying to do this to decide whether to redirect stdin to a file or not: [ ...some condition here... ] && input=$fileName || input="&0" ./myScript < $input But that doesn't work because when the variable $input is "&0", bash interprets it as a filename. However, I could just do: if [ ...condition... ];then ./myScript <$file...

Bash scripting: How do I parse the output of a command and perform an action based on that output?

I am using wget to grab some files from one of our servers once an hour if they have been updated. I would like the script to e-mail an employee when wget downloads the updated file. When wget does not retrieve the file, the last bit of text wget outputs is file.exe' -- not retrieving. <blank line> How do I watch for that bit of text...

How do I use su to execute the rest of the bash script as that user?

I've written a script that takes, as an argument, a string that is a concatenation of a username and a project. The script is supposed to switch (su) to the username, cd to a specific directory based upon the project string. I basically want to do: su $USERNAME; cd /home/$USERNAME/$PROJECT; svn update; The problem is that once ...

bash function to prompt for and return input

I'm trying to write a helper function to use in a bash script to take a variable prompt string and return the value the user inputs. What I have sits and waits for a user to input the value without displaying the prompt first, which is puzzling. It also stores the echo in the return value ($foo), and doesn't keep the value read in with...

search multiple php files, and replace text ?

i have several php files, and there's references to .html files in those. I need to replace ".html" to ".php" how can i do this in bash ? ...

Mysql for python

I had trouble installing a local installation of mysql, so I have a connection to a remote mysql database via an IP tunnel, I connect to it via typing localhost in perl and python scripts. Something weird is happening and I want to check the connection from the command line rather than the script. Is there a BASH command line that I ca...

Sed move text to beginning of line?

I have a variable with the contents "eth0 eth1 bond0", is there a way using sed or a similar tool to move anything matching bond.* to the beginning of the line? ...

Bash insert a comma (,) after every third field of a variable or array?

I have a variable with the following contents: "a b c d e f g h i j k l", how would you go about adding a comma sign (,) after each third member so it looks like this: "a b c, d e f, g h i, j k l". Initially all my variable data is stored in an array so if anyone knows how to directly manipulate the array, it would be great. Thanks in ...

reading stdin multiple times in bash

Hi, I'm trying to read from stdin multiple times in a shell script, with no luck. The intention is to read a list of files first (which are read from the stdin pipe), and then read twice more to get two strings interactively. (What I'm trying to do is read a list of files to attach in an email, then the subject and finally the email b...

bash: calling a scripts with double-quote argument

Hi, I have a bash scripts which an argument enclosed with double quotes, which creates a shape-file of map within the given boundries, e.g. $ export_map "0 0 100 100" Within the script, there are two select statements: select ENCODING in UTF8 WIN1252 WIN1255 ISO-8859-8; ... select NAV_SELECT in Included Excluded; Naturally, these ...

Running bash shell in Maemo

I have attempted to run the following bash script on my internet tablet (Nokia N810 running on Maemo Linux). However, it doesn't seem that it is running, and I have no clue of what's wrong with this script (it runs on my Ubuntu system if I change the directories). It would be great to receive some feedback on this or similar experiences ...

Rscript: Define path file as argument

I try this command : Rscript "/Users/test/Scripts/arg_test.R" "path_in=/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv" path_in2="/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv" but I have this error : Error in parse(text = args[[i]]) : unexpected '/' in "path_in=/" Part of Rscript : args=(commandArg...

Redirecting standard output to new file adds strange character to end of filename in cygwin

I'm having trouble with a shell script in Cygwin. The specific command that's causing the problem is this: sed -e "s/6.0.[0123456789]\{1,\}/6.0.${REV}/g" "path/to/file/config.xml" > "path/to/file/config.xml.tmp" The problem is that the file is being created with a strange character at the end, so instead of being named config.xml.tmp,...

Bash: Why is echo adding extra space?

I get: $ echo -e "D"{a,b,c}".jpg\n" Da.jpg Db.jpg Dc.jpg Note: The extra spaces before Db and Dc on the 2nd and 3rd line of the output. Why are these there? Thanks, Dan Edit: Since my actual objective had spaces in it (which I should have written originally): echo -e "Name"{,.}" "{-,}"extra"{,so}" 5v5 "{one,two,No\ four}{,!,\!\!...