|
From: | Jonathan Kulp |
Subject: | Re: manipulating .ly with bash - echo drops \ |
Date: | Wed, 26 Nov 2008 11:36:55 -0600 |
User-agent: | Thunderbird 2.0.0.18 (X11/20081125) |
Rob Canning wrote:
Rob Canning wrote:hello,i have generated a lilypond file and would like to be able to manipulate the file with bash scripts. first thing i would like to do is insert some additional stuff one line under the 'version "2.10" line. the script i have is below - the problem is the echo "$line" bit drops all the \ from the score.anyone know a way to fix this script so all the \ remain intact? thanks rob # usage: ./insert.sh mainfile insertedfile >outputfile cat "$1" | while read line do echo "$line" if [[ "$line" == 'version "2.10"' ]] then cat "$2" fi donethis is my dirty solution # usage: ./insert.sh mainfile insertedfile >outputfile sed 's/\\/\\\\/g' "$1" | while read line do echo "$line" if [[ "$line" == '\version "2.10"' ]] then cat "$2" fi done
Glad you've found a solution already. This stuff interests me so I fiddled around until I got it to do what I thought you were trying to do. Are you trying to append text to the first argument if it's version 2.10? If so then here's how I did it, although it can only append at the end of the file, it can't stick it somewhere in the middle.
#!/bin/bash # usage: ./insert.sh mainfile insertedfile outputfile # read contents of first argument and look for 2.10, then # check return status version=$(cat "$1" | grep "2.10" ; echo $?) # define full text of first arg text=$(cat "$1") # define source of text to be inserted newtext=$(cat "$2") # if return status is 0, then it found 2.10 in the file # and will append text from arg 2 and redirect to # filename given as arg 3 if [ "$version" == "0" ] ; then echo "$text" "$newtext" > "$3" else echo "version is already 2.11" fi [END] Even if this wasn't what you were looking for I had fun doing it :). Best, Jon -- Jonathan Kulp http://www.jonathankulp.com
[Prev in Thread] | Current Thread | [Next in Thread] |