bash

Using awk create two arrays from two column values, find difference and sum differences, and output data

I have a file with the following fields (and an example value to the right): hg18.ensGene.bin 0 hg18.ensGene.name ENST00000371026 hg18.ensGene.chrom chr1 hg18.ensGene.strand - hg18.ensGene.txStart 67051161 hg18.ensGene.txEnd 67163158 hg18.ensGene.exonStarts 67051161,67060631,67065090,67066082,67071855,67072261,67073896,67075980,67078739...

create a rolling buffer in bash

I want to use curl to get a stream from a remote server, and write it to a buffer. So far so good I just do curl http://the.stream>/path/to/thebuffer. Thing is I don't want this file to get too large, so I want to be able to delete the first bytes of the file as I simultaneously add to the last bytes. Is there a way of doing this? A...

bash shell script for 100 iteration and log time taken

How do I run 100 iterations using a bash shell script? I want to know how long will it take to execute one command (start and end time). I want to keep track which iteration is currently running. I want to log each iteration. I have one automated script I need to run and log it. for i in 1 2 3 do command1 done But I want to know...

get list of sections from ini-file using bash (sed/awk)

I want to create a var from the section names of an ini file like: [foo] ; ... [bar] ; ... [baz:bar] ;... now I need a var like SECTIONS="foo bar baz" thanks in advance ...

Running bash function in command of su

In my bash script I execute some commands as other user. I want to call a bash function in command of su I defined in my script before. my_function() { do_something } su username -c "my_function" The above script doesn't work, of course my_function is not defined inside su. I have only the idea to save the function into separate fi...

Linux change group permission to match owner permissions

Suppose I have a directory on Linux with a bunch of files and subdirectories. This is that root directory: drwxr-xr-x 13 user1 group1 4096 May 7 15:58 apps Now, I only want to alter the group portion of those permissions. I want to alter it such that it matches exactly the owner portion. The result for that directory would be: d...

Git add submodules to super project from existing repos

Hi I have several (about 10-15) Git repositories in a directory: ~/plugins/admin ~/plugins/editor ~/plugins/etc Each have their own separate repository and remote server. The problem is that to pull all the changes from all the repositories I have to: cd ~/plugins/admin git pull origin master password: ******** cd .. cd ~/plugins/...

combine two lists with a join on a column

I'm trying to combine two lists, joining them by a common field suchs as ENST00000371026. I've tried the following but no luck. What is the actual way to do it? cat> gar1.txt <<EOF ENST00000371026 ENSG00000152763 ENST00000371023 ENSG00000152763 ENST00000395250 ENSG00000152763 ENST00000309502 ENSG00000163485 ENST00000377464 ENSG00000142...

How to update $PATH

I am writing a python/pygtk application that is adding some custom scripts (bash) in a certain folder in $HOME (eg. ~/.custom_scripts). I want to make that folder available in $PATH. So every time the python app is adding the script, that script could be instantly available when the user is opening a terminal (eg. gnome-terminal). Wh...

Global bash alias from script

I'd like to create alias by script, and use it in bash. Namely: #!/bin/bash alias mycmd="ls -la" Bash: login@host ~$: ./script login@host ~$: mycmd *ls output* Of course, alias should be available just for one session (not .bashrc etc). Is it possible? Unfortunately I have not found a solution. ...

How do you type a tab in a bash here-document?

The definition of a here-document is here: http://en.wikipedia.org/wiki/Here_document How can you type a tab in a here-document? Such as this: cat > prices.txt << EOF coffee\t$1.50 tea\t$1.50 burger\t$5.00 EOF UPDATE: Issues dealt with in this question: Expanding the tab character While not expanding the dollar sign Embedding a he...

Difference between local a and local a=

Hi, from /lib/lsb/init-functions (maybe this file is debian specific, but doesn't really matter for the question): pidofproc () { local pidfile line i pids= status specified pid pidfile= specified= Whats the difference between saying local a and local a= ? ...

How do I detect plaintext in a MIME file?

I have a large set of MIME files, which contain multiple parts. Many of the files contain parts labelled with the following headers: Content-Type: application/octet stream Content-Transfer-Encoding: Binary However, sometimes the contents of these parts are some form of binary code, and sometimes they are plaintext. Is there a clev...

file search bash script

i am trying to make a very simple bash script to find files matching the given name in the directory structure of the current directory. So, I used the find function like this ARGS=1 E_BADARGS=65 E_NOFILE=66 if [ $# -ne "$ARGS" ] # Correct number of arguments not passed then echo "Usage: `basename $0` filename" exit $E_BADARGS fi...

bash filename globbing - operate on files starting with capital

Hi, Lets say I have a folder with the following jpeg-files: adfjhu.jpg Afgjo.jpg Bdfji.jpg bkdfjhru.jpg Cdfgj.jpg cfgir.jpg Ddfgjr.jpg dfgjrr.jpg How do I remove or list the files that starts with a capital? This can be solved with a combination of find, grep and xargs. But it is possible with normal file-globbing/pattern m...

Change Default Group in Script

Is it possible to change a user's default group inside a script for the duration of that script's execution? I need to generate files in a script that have the proper user and group but my user's primary group is not who should own the resultant output. $ groups groupa groupb $ ./myscript.sh $ ls -l -rw-r--r-- 1 me groupa 0 Sep 1...

Bash scripting: parameter substitution problem

Hi there, I'm trying to write a simple bash script but something seems wrong, I'm testing the following on the command line: DATE="2010-09-{10,11}" result=`\ls *ext.$DATE.Z` and results in ls: cannot access *ext.2010-09-{10,11}.Z: No such file or directory but if I execute this: result=`\ls *ext.2010-09-{10,11}.Z` it works flawle...

Is there a better way to run a command N times in bash?

I occasionally run a bash command line like this: n=0; while [[ $n -lt 10 ]]; do some_command; n=$((n+1)); done To run some_command a number of times in a row -- 10 times in this case. Often some_command is really a chain of commands or a pipeline. Is there a more concise way to do this? ...

From within a bash script, how do I create a new filename, place a $variable in part of it?

Within a loop in my bash script, I am 'doing work', then writing the result of each iteration to its own file. I'd like to name these files # User-defined Function (UDF) processLine(){ line="$@" # get all args index=$(echo $line | gawk -F::: '{ print $1 }') content=$(echo $line | gawk -F::: '{ print $2 }') # Let's tr it to remove do...

Linux bash read output explanation

Hi, I would like to understand the values I get from read command in console. Are these outputs combinations of some keys? F2 ^[OQ F3 ^[OR F4 ^[OS ESC ^[ My problem is that I use special 128 keys keyboard that is programmed for specific software. I need to send these "keys" into this software using code below. Don't be confuse...