bash

How to pipe stderr, and not stdout?

I have a problem that writes information to stdout and stderr, and I need to grep through what's coming to stderr, while disregarding stdout. I can of course do it in 2 steps: command > /dev/null 2> temp.file grep 'something' temp.file but I would prefer to be able to do is without temp files. Any smart piping trick? ...

picking a random line from stdout

I have a command which spouts a number of lines to stdout: $ listall foo bar baz How do I extract a random entry from this, in a one-liner (preferably without awk) so I can just use it in a pipe: $ listall | pickrandom | sed ... | curl ... Thanks! ...

use regular expression in if-condition in bash

Hi, I wonder the general rule to use regular expression in if clause in bash? Here is an example $ gg=svm-grid-ch $ if [[ $gg == *grid* ]] ; then echo $gg; fi svm-grid-ch $ if [[ $gg == ^....grid* ]] ; then echo $gg; fi $ if [[ $gg == ....grid* ]] ; then echo $gg; fi $ if [[ $gg == s...grid* ]] ; then echo $gg; fi $ ...

Running Python With STDIN From Bash

I have a bash code (Mybash1.sh) where the result I need to pass to another bash code (Mybash2.sh) that contain Python Here are the codes. Mybash1.sh #! /bin/bash # Mybash1.sh cut -f1,3 input_file.txt | sort | ./Mybash2.sh Mybash2.sh is this: #! /bin/bash #Mybash2.sh python mycode.py foo.txt <("$@") > output.txt # do something for...

bash script running string as command

i have a bash script that builds a string to run as a command the script: #! /bin/bash matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/" teamAComm="`pwd`/a.sh" teamBComm="`pwd`/b.sh" include="`pwd`/server_official.conf" serverbin='/usr/local/bin/rcssserver' cd $matchdir illcommando="$serverbin include='$include' server...

Command-line parameters in Shell Script?

I am trying to include this du -s *|awk '{ if ($1 > 3000) print }' in a shell script, but I want to parameterize the 3000. However, since the $1 is already being used, I'm not sure what to do. This was a total failure: size=$1 du -s *|awk '{ if ($1 > $size) print }' How can I pass a parameter in place of 3000 in the first script ab...

using if elif fi in shell scripts

Hello, I'm not sure how to do an if with multiple tests in shell, I'm having trouble writing this script: echo "You have provided the following arguments $arg1 $arg2 $arg3" if [ "$arg1" = "$arg2" && "$arg1" != "$arg3" ] then echo "Two of the provided args are equal." exit 3 elif [ $arg1 = $arg2 && $arg1 = $arg3 ] then echo "...

Bash while loop calling a Python script

I would like to call a Python script from within a Bash while loop. However, I do not understand very well how to use appropriately the while loop (and maybe variable) syntax of the Bash. The behaviour I am looking for is that, while a file still contains lines (DNA sequences), I am calling a Python script to extract groups of sequences ...

How to open an editor from a bash function?

...

shell float number in expr

I'm trying to get a float number from this : totalmark=$(expr $sum / $subjects ) Is this correct? ...

Bash scripting, checking for errors, logging

Here's one for the bash-fu wizards. No, actually, I'm just kidding, you'll all probably know this except for me.. I'm trying to create a backup shell script. The idea is fairly simple: find files in a certain folder, older than 7 days, tar/gzip them to another directory, and remove them. The problem is, I'm not sure if I'll have enough ...

Bash: Subprocess access variables

I want to write a Bash-Script which loggs into several machines via ssh and first shows their hostname and the executes a command (on every machine the same command). The hostname and the output of the command should be displayed together. I wanted a parallel version, so the ssh-commands should be run in background and in parallel. I co...

Great tools to find and replace in files?

I'm switching from a Windows PHP-specific editor to VIM, on the philosophy of "use one editor for everything and learn it really well." However, one feature I liked in my PHP editor was its "find and replace" capability. I could approach things two ways: Just find. Search all files in a project for a string, see all the occurrences li...

Bash script not quite matching

I want to cat an apache log and then output the result to a file. I want to match the day/month with the Apache log to the current/previous date, however I seem to be doing this incorrectly. Sample from apache log: 62.173.92.62 - - [02/Mar/2010:15:46:58 +0000] "GET /img....... Current script: cat access_log | grep "\[+%d+/%b" > email....

Asynchronous shell commands

I honestly can't believe I can't find a solution for this online. I've run across a few things that seem similar, but nothing that really does what I want... I'm trying to use a shell script to start a command. I don't care if/when/how/why it finishes. I want the process to start and run, but I want to be able to get back to my shell im...

Detect directory changes in unix

How could I track changes of specific directory in UNIX? For example, I launch some utility which create some files during its execution. I want to know what exact files were created during one particular launch. Is there any simple way to get such information? Problem is that: I cannot flush directory content after script execution Fi...

Issue with echo and tab in Bash

Hey, I would like to know if its possible to do formatting using echo in shell scripting. Here is a small code snippet which is giving me the problem echo -en "\rFileName : $filename : $index of $lines Completed" The Filename's is a string with varying length and this is causing problem with formating in the terminal. How ...

How to convert timestamps to dates in bash?

I need a shell command or script that converts a UNIX timestamp to a date. The input can come either from the first parameter or from stdin, allowing for the following usage patterns: ts2date 1267619929 and echo 1267619929 | ts2date Both commands should output "Wed Mar 3 13:38:49 2010". ...

Using sed to mass rename files

Objective Change these filenames: F00001-0708-RG-biasliuyda F00001-0708-CS-akgdlaul F00001-0708-VF-hioulgigl to these filenames: F0001-0708-RG-biasliuyda F0001-0708-CS-akgdlaul F0001-0708-VF-hioulgigl Shell Code To test: ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \1\2/' To perform: ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \...

Assign a makefile variable value to a bash command result ?

Hello , I'm trying to assign the output of this command ( that is in my makefile ) to the makefile HEADER var like in this following line of code: HEADER = $(shell for file in `find . -name *.h`;do echo $file; done) The problem is that if I print HEADER in my makefile using: print: @echo $(HEADER) I get ile ile ile ile ile il...