bash

Mixing regular expression and other conditional expression in a bash if statement

I can't get around this for quite sometime now. As I read along manuals and tutorials I'm getting more confused. I want an if statement with the following logic: if [ -n $drupal_version ] && [[ "$drupal_version" =~ DRUPAL-[6-9]-[1-9][1-9] ]]; then but I can't get it to work properly. When the script is evaluated using the "bash -x .....

select fields with sed

Hey, Using only grep and sed, is there a way I can tranform the output of ls -l * into this : -rw-r--r-- agenda.txt -rw-r--r-- annuaire.txt Thanks! ...

Fastest way to sort files

Hi, I have a huge text file with lines like: -568.563626 159 33 -1109.660591 -1231.295129 4.381508 -541.181308 159 28 -1019.279615 -1059.115975 4.632301 -535.370812 155 29 -1033.071786 -1152.907805 4.420473 -533.547101 157 28 -1046.218277 -1063.389677 4.423696 What I want is to sort the file, depending on the ...

How to assign the output of a command to a variable?

Hi, this is probably a very stupid question; in a bash script, given the output of, for instance; awk '{print $7}' temp it gives 0.54546 I would like to give this to a variable, so I tried: read ENE <<< $(awk '{print $7}' temp) but I get Syntax error: redirection unexpected Could you tell me why, and what is the easiest way t...

Find float in a text file

Hi, I am trying to find some float number (like -1234.5678) in a huge text file using grep, so I thought about: grep -n '-1234.5678' but I get errors, do you know what is the right way using grep and why? there is anything easier? Thanks ...

Substitution till the end of the line in bash

Hi, I have a huge text file with lots of lines like: asdasdasdaasdasd_DATA_3424223423423423 gsgsdgsgs_DATA_6846343636 ..... I would like to do, for each line, to substitute from DATA_ .. to the end, with just empty space so I would get: asdasdasdaasdasd_DATA_ gsgsdgsgs_DATA_ ..... I know that you can do something similar with: ...

bash_completion not working, source command not found.

I recently inherited a Ubuntu Hardy box that acts rather funky out-of-the-box. The first things I tried to do was edit my .bashrc profile to do some coloring and add some aliases I usually have, but then when I try to source the ~/.bashrc I get sh: source: not found and I have also noticed tabbed autocomplete is also not working at all -...

Substitution after the end of the word

Hi, I have a huge text file with lots of lines like: a 23232 23232 545 3434 DATA4545454_1 454 4646466 3434 3567 a 23232 23267632 545 3436764 DATA454545567564__1 454 464675466 3434 3 a 232676732 232676732 545 3434 DATA4545454_1 454 46457566466 3457534 35675 In all of them I would like to get rid of everything which is after DATA*, so ...

Extract substructure from a text file using bash or python

Hi, I have a huge text file, which follows the structure: SET TAG1 ... ... SET ... SET TAG2 ... ... SET ... ... I would like to extract for a specific TAG, (i.e. TAG54) its individual "substructure", which would be SET TAG54 ... ... SET Each substructure, for a given TAG_i contains always: first line:SET second line:TAG_i (in thi...

Unix file naming convention for effective tab completion?

I feel like I often name files in such a way that my computer constantly beeps while I program because the tab completion is ambiguous. Before doing a lot of Unix programming, I tended to name related files with the same prefix to indicate their relation. Now I must re-think my approach to folder and file structures and names to program ...

Bash: for loop, copy, backup

Hey, not 100% sure what this error means. % for f in "*" ; do cp $f ../backup/backup$f ; done cp: ../backup/backup* not found The purpose is to copy all the files into a folder into a backup folder and rename the files to backup. ...

Removing final bash script argument

I'm trying to write a script that searches a directory for files and greps for a pattern. Something similar to the below except the find expression is much more complicated (excludes particular directories and files). #!/bin/bash if [ -d "${!#}" ] then path=${!#} else path="." fi find $path -print0 | xargs -0 grep "$@" Obviou...

How can I prevent default_environment variables from getting set by Capistrano's sudo action?

My deploy.rb sets some environment variables to use the regular user's local Ruby rather than the system-wide one. set :default_environment, { :PATH => '/home/myapp/.rvm/bin:/home/myapp/.rvm/bin:/home/myapp/.rvm/rubies/ruby-1.9.1-p378/bin:/home/myapp/.rvm/gems/ruby-1.9.1-p378/bin:/home/myapp/.rvm/gems/ruby-1.9.1-p378%global/bin:/home/...

Editing history in bash

In bash, when I go back in history, edit some command and run it, this edited command is appended to history and the original one is left intact. But every once in a while I somehow manage to affect the original command, i.e. my edit replaces the original command back in history. I can't put my finger on how this happens. Can someone exp...

Unable to set variables in bash script in Mac OSX

Hello! I am attempting to automate moving files from a folder to a new folder automatically every night using a bash script run from applescript on a schedule. I am attempting to write a bash script on Mac OSX, and it keeps failing. In short this is what I have (all my ECHOs are for error checking): #!/bin/bash folder = "ABC" useracct...

Is there any way to get a list of connected servers in OS X? (Bash, Obj C, AppleScript...)

Simply, I'm just looking to get a list of connected remote disks. I have a script right now that compares /Volumes/ to "diskutil -list" but that only gives me the name of the remote disks, not the actual address. Anyone have ideas as to how I might go about doing this? Thanks in advance. ...

Cat with new line

My input file content is welcome welcome1 welcome2 My script is for groupline in `cat file` do echo $groupline; done I got the following output. welcome welcome1 welcome2 Why it is not print the empty line. I want the reason. ...

Sed does not work in expect

I made this bash one-liner which I use to list Weblogic instances running along with their full paths.This works well when I run it from the shell. /usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed 's/weblogic.policy//' | sed 's/security\///' | sort I tried to incorpora...

Bash: Syntax error: redirection unexpected

I do this in a script: read direc <<< $(basename `pwd`) and I get: Syntax error: redirection unexpected in an ubuntu machine /bin/bash --version GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu) while I do not get this error in another suse machine: /bin/bash --version GNU bash, version 3.2.39(1)-release (x86_64-suse-li...

Bash: ambiguous redirect

Hi, I get in a bash script, in the follwoing line echo $AAAA" "$DDDD" "$MOL_TAG >> ${OUPUT_RESULTS} the error: line 46: ${OUPUT_RESULTS}: ambiguous redirect Why? Thanks ...