Posted in Shell Scripting on February 1st, 2007 11 Comments »
say you’ve got a stream of filenames that you’d like to remove. for instance, i’ve got a bunch of filenames that pop out of this command: grep -v “,” `search “boot0.txt”` | sed ‘s/boot.*//’ turns out i can’t directly pipe this to rm. instead, i’ve got to use the xargs command, as so: grep -v […]
Posted in Shell Scripting on January 31st, 2007 20 Comments »
to let the variable ‘j’ equal the output of a shell command, such as find, try: j=$(find `echo $i | sed ‘s/AnGST\/.*/AnGST\//’` -name “*.seq”) basically, it looks like all you need to do is enclose the command with a dollar-sign and some parentheses. now, your shell scripts won’t need to be populated by unending lines […]
Posted in Shell Scripting on January 29th, 2007 3 Comments »
i’ve just discovered sed. this thing is wonderful; it’s like an in-line perl on the command-line. now, it looks like i can use the shell to do things that even a perl program would be overkill for. for instance, i’ve got these files: [ldavid@subtilis data]$ ls ECprot119.phy  ECprot1519.phy ECprot19.phy   ECprot2519.phy ECprot1219.phy ECprot1619.phy ECprot2019.phy ECprot3119.phy ECprot1319.phy […]
Posted in Shell Scripting on December 20th, 2006 No Comments »
here’s a shell for executing a ‘for loop’ on the bash command-line: for i in `ls boot*`; do echo $i; done
Posted in Shell Scripting on December 12th, 2006 2 Comments »
a simple task you might want to do in a shell script is perform some operation on every file in a directory. here’s the shell of code to do that: #!/bin/sh # iterate through all sequence files in this directory for phy_file in `find $1 -name “*.phy”` do echo $phy_file; done here, i’m stepping through […]
Posted in Shell Scripting on October 3rd, 2006 7 Comments »
to get the length of a string in the bash shell: ${#str_var}