Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

I'm writing a bash script that involves a long series of pipes. I also want to make it readable.

Is there a simple way to put these on multiple lines and making bash treat it as one single line of input?

code:
from
command 'args' $1 |anothercommand|yetanother|...|nthcommand

to  
command 'args' $1 
|anothercommand
|yetanother
|...|
|...nthcommand
Sort of the opposite of a semicolon!

Adbot
ADBOT LOVES YOU

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

6174 posted:

What you are looking for is called a line continuation character. In the case of bash it is \

Oh yes it is. My error was caused by something else. :blush:

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

Here's my very ugly take on it!

echo "16(100%)" |sed 's/[()%]/ /g'|awk '{print $2}'

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

I'm making a bash script where I need to echo $VARIABLE number of something on a line, let's say Xs.

Like this, the unknown command is [?]:

alice=5
bob=7
echo "Alice [?]"
echo "Bob [?]"


...and get this output:

Alice XXXXX
Bob XXXXXXX

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

Plastic Jesus posted:

I totally misread this and thought that you wanted to print the number of characters in a string. Which is actually awesome because I learned how to find out the length of a string in bash (it's ${#var_name} btw).

All that you need to do is
code:
alice=5
for(( i = 0; i < alice; i++ ))
do
   echo -n "X"
done
echo

That was exactly what I needed. That get lenght of a string thing will be very useful for me too. I did that by

stringlength=`echo $string | wc -l`

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

In bash, is there a way to redirect stdout to a command that works on files?

I have a list that I'd like to compare to another list using comm. One of the lists is created by a [long tangle of seds, awks and greps], while the other is a file (mylist). The command comm only takes input as files.

Do I have to go by a temp file, or is there some way to get comm to work with the stdout?

from:
[long tangle of seds, awks and greps] >tempfile
comm tempfile mylist

to:
comm mylist [long tangle of seds, awks and greps]

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

floWenoL posted:

Yes. You want "comm mylist <(long tangle of seds awks and greps)". Under the hood, bash replaces <(...) with something like /dev/fd/XXX which is the dev path to the stdout of the process.

Thank you! This is extremely useful.

I haven't seen this in any of the many bash tutorials/tips/tricks I've seen online. This is as useful as 2>&1 !

Adbot
ADBOT LOVES YOU

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

This is a bash/shellscript question:

I have file with lots of DNA sequences in them. Missing letters are replaced by -s. They look like this:

-----AACGCT--TTGGT--
-GG-TAACGCT--TTGGT--
TGG-AACGCT---TTGGTCC


I want to replace the leading and trailing, but not internal, -s of each line with ?s to get this result:

?????AACGCT--TTGGT??
?GG-TAACGCT--TTGGT??
TGG-AACGCT---TTGGTCC


Finding the leading and trailing -s is an easy regexp ( ^[-]* and [-]*$ ), but is there an efficient way to replace them with the same number of ?s ?

Now I'm using a horrible and slow sed script to do that.

code:
sed 's/^-/\?/' myfile >leadingdeleter1
var0=0
while [ " $var0" -lt "$LIMIT" ]
do
        sed 's/\?-/\?\?/' leadingdeleter1 > leadingdeleter2
        sed 's/\?-/\?\?/' leadingdeleter2 > leadingdeleter1
let "var0 += 1"
done
I prefer to stay in shellscript, but if perl would be much more efficient, I'll try that.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply