bash

ls color schemes

What's your favorite color scheme for ls in bash? There's lots of vim color schemes out there, but I'm having trouble finding any for ls. Does anyone know any good websites with sample ls color schemes? If you've made a custom one, attach a screenshot, along with the line to put in ~/.bash_profile. export LSCOLORS=DxGxcxdxCxegedabag...

numeric cycles in shell

hello, what is the name and syntax of the construction ((..)) in example below? for ((i=1;i<10;i++)) do echo $i; done it has strange variable i where are other constructions for numeric cycling in shells? ...

wget: dont follow redirects

How do I prevent wget from following redirects? ...

Extract File Basename Without Path and Extension in Bash

Given file names like these: /the/path/foo.txt bar.txt I hope to get foo bar Why this doesn't work? #!/bin/bash fullfile=$1 fname=$(basename $fullfile) fbname=${filename%.*} echo $fbname What's the right way to do it? ...

Writing from an array to a file bash and new lines

I'm trying to write a script the generates a template file for Pashua (a perl script for creating GUI on osx) I want to crate an instance for each item in the array, so the ideal output would be: AB1.type = openbrowser AB1.label = Choose a master playlist file AB1.width=310 AB1.tooltip = Blabla filesystem browser AB2.type = openbrowse...

How to get a substring in awk

This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 0.50 0.50 0.50 -43.00 100010101101110101000111010 And an awk command that checks a certain position if it's a "1" or "0" at column 13 Something like: awk -v values="${values}" '{if (substr($13,1,1)==1) printf values,$1,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}' fo...

Merge two text files at a specific location, sed or awk.

I have two text files, I want to place a text in the middle of another, I did some research and found information about adding single strings: I have a comment in the second text file called STUFFGOESHERE, so I tried: sed '/^STUFFGOESHERE/a file1.txt' file2.txt sed: 1: "/^STUFFGOESHERE/a long.txt": command a expects \ followed by te...

Parsing result of Diff in Shell Script

I want to compare two files and see if they are the same or not in my shell script, my way is: diff_output=`diff ${dest_file} ${source_file}` if [ some_other_condition -o ${diff_output} -o some_other_condition2 ] then .... fi Basically, if they are the same ${diff_output} should contain nothing and the above test would evaluate to tr...

Extracting shell script from parameterised Hudson job

I have a parameterised Hudson job, used for some AWS deployment stuff, which in one build step runs certain shell commands. However, that script has become sufficiently complicated that I want to "extract" it from Hudson to a separate script file, so that it can easily be versioned properly. The Hudson job would then simply update from ...

how can i use regex to get a certain string of a file

Hi with linux bash shell , how can i use regex to get a certain string of a file by example: for filename *.tgz do "get the certain string of filename (in my case, get 2010.04.12 of file 2010.01.12myfile.tgz)" done or should I turn to perl Merci frank ...

Equivalent of print "-"x20 of perl in Bash or command line

In perl you can simply write print "-" x 20 and you get a line with dashes...but i need the same thing in bash/commandline on linux without perl/(g)awk etc. any ideas? The intention is to use it in the -exec of the find command and i want to prevent using simple echo "---------" ... ...

How to sort output of "s3cmd ls"

Amazon "s3cmd ls" takes like this output: 2010-02-20 21:01 1458414588 s3://file1.tgz.00 2010-02-20 21:10 1458414527 s3://file1.tgz.01 2010-02-20 22:01 1458414588 s3://file2.tgz.00 2010-02-20 23:10 1458414527 s3://file2.tgz.01 2010-02-20 23:20 1458414588 s3://file2.tgz.02 How to select all files of archive, ending at 00 ... XX...

Writing " to a file in bash.

Simply I need to write "echo" t${count} = "$"t${count}" To a text file, including all the So the output would be something like: echo " t1 = $t1" With " as they are. So I have tried: count=1 saveIFS="$IFS" IFS=$'\n' array=($(<TEST.txt)) IFS="$saveIFS" for i in "${array[@]}" do echo "echo" t${count} = "$"t${count}"" (( count++ ))...

Printf example in bash does not create a newline

Working with printf in a bash script, adding no spaces after "\n" does not create a newline, whereas adding a space creates a newline, e. g.: No space after "\n" NewLine=`printf "\n"` echo -e "Firstline${NewLine}Lastline" Result: FirstlineLastline Space after "\n " NewLine=`printf "\n "` echo -e "Firstline${NewLine}Lastline" R...

Using BASH - Find CSS block or definition and print to screen

I have a number of .css files spread across some directories. I need to find those .css files, read them and if they contain a particular class definition, print it to the screen. For example, im looking for ".ExampleClass" and it exists in /includes/css/MyStyle.css, i would want the shell command to print .ExampleClass { color: #ff00...

How can I change 0123 into ACTG with tr or Perl?

I have a file with such list: 100 101 102 103 What I want to do is to replace every 0 into A, 1 into C, 2 into G, 3 into T. Hence we hope to get CAA CAC CAG CAT ...

String Manipulation in Bash . . . Removing leading section

This is probably a really stupid question...but how can I remove parts of a string up to a certain character? Ex.) If I have the string testFile.txt.1 and testFile.txt.12345 how can I remove the 1 and 12345? Thanks a lot for the help EDIT: Sorry it was really unclear. I meant to remove and throw away the first part of a string up to a...

Float conditional in bash

Hi, in bash I need to compare two float numbers, one which I define in the script and the other read as paramter, for that I do: if [[ $aff -gt 0 ]] then a=b echo "xxx "$aff #echo $CX $CY $CZ $aff fi but I get the error: [[: -309.585300: syntax error: invalid arithmetic operator (error ...

How to detect if a script is being sourced

I have a script where I do not want it to call 'exit' if it's being sourced. Initially I though checking if $0 == bash but this has problems if the script is sourced from another script, or if the user sources it from ksh. Is there a reliable way of detecting if a script is being sourced? ...

process killed -- delete output file?

I have a bash script that runs on our shared web host. It does a dump of our mysql database and zips up the output file. Sometimes the mysqldump process gets killed, which leaves an incomplete sql file that still gets zipped. How do I get my script to 'notice' the killing and then delete the output file if the killing occurred? Edit: ...