Feed on
Posts
Comments

Archive for the 'Shell Scripting' Category

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 […]

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 […]

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  […]

here’s a shell for executing a ‘for loop’ on the bash command-line: for i in `ls boot*`; do echo $i; done

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 […]

to get the length of a string in the bash shell: ${#str_var}

« Prev