Sed help

Hi
I am trying to get rid of " " in a txt file with sed
although can't get it to work...(i am not very experinced with sed)
anyway, I have a txt file whic looks like this:
"hi" "there" "we" "like" "sed
and I wanna separate everythng so that i can get an output like
hi
there
and so on...
anyone who knows sed that can help me?

that sounds like something I can use
I will most certainly try it
thanks !
Update: Doesn't quite do what I want,
I insert my whole code in here:
# INSTEAD OF SHOWING "INSTALL" in the dialog --checklist i wannt it to have a description, how this is done, I don't know...maybe someone does?!
select_install()
dodialog msgbox "In the next stage you are going to choose which packages to install, recommendation is that you install all packages." 18 70
CHKLIST=
if [ "$MODE" = "install" ]; then
PKGS=$PKGS_PATH
fi
# INSTEAD OF SHOWING "INSTALL" in the dialog --checklist i wannt it to have a description, how this is done, I don't know...maybe someone does?!
for app in `sed 's|"||g' $PKGS | awk '{ print $1 }'`; do
CHKLIST="$CHKLIST $app INSTALL ON"
done
if [ -e /tmp/.pkglist ]; then
rm /tmp/.pkglist
fi
domenu checklist "Select Packages" 19 55 12 $CHKLIST 2>/tmp/.pkglist || return 1
if [ $? == 0 ]; then
install
else
mainmenu
fi

Similar Messages

  • Sed help pls

    Hi,
    I have a bounch of files wich are named like "something_sXX_otherthing_YYYY", where sXX can be s01,s02....s99, YYYY is 0001,0002, .... 9999.
    I'd like to extract the sXX part from the filenames to sort them, can somebody help me how to do in a bash script?
    like if I have wildlife_s02_lion_0003.jpg, i'd like to get the "s02" string.
    I tried with sed 's/[^s0-91-9]//g', but that way it extracts the also other numbers and s characters.
    Thank you!

    How exactly are you wanting to sort them? Are you wanting to rename files  or just see a visual sorted list of them?
    If it's a visual then do you really need to extract "Sxx" just to sort them?
    How about just letting sort do it for you?
    Example:
    [harry ~]$ cat file
    bar_s47_dog_0024.jpg
    foo_s01_snail_0001.jpg
    bar_s02_dog_0002.jpg
    baz_s03_dog_0003.jpg
    bar_s02_cow_0001.jpg
    baz_s03_bird_0001.jpg
    Use sed to get rid of the underscores temporarily and make them blanks. Now we have clear fields to work with.
    [harry ~]$ cat file | sed 's/_/ /g'
    bar s47 dog 0024.jpg
    foo s01 snail 0001.jpg
    bar s02 dog 0002.jpg
    baz s03 dog 0003.jpg
    bar s02 cow 0001.jpg
    baz s03 bird 0001.jpg
    Use sort to first, sort by the first field (dictionary order), the third field (also dictionary order), and finally by the fourth field (numeric order). Then another quick sed to replace the underscores and your in business.
    Full Command:
    [harry ~]$ cat file | sed s'/_/ /g' | sort -k1,1d -k3,3d -k4,4n | sed 's/ /_/g'
    bar_s02_cow_0001.jpg
    bar_s02_dog_0002.jpg
    bar_s47_dog_0024.jpg
    baz_s03_bird_0001.jpg
    baz_s03_dog_0003.jpg
    foo_s01_snail_0001.jpg
    Also, if all you really want is the "Sxx" then how about: (Regex could be finer tuned but but gets the job done in this situation.)
    [harry ~]$ grep -Eo '[Ss][[:digit:]]+' file
    s47
    s01
    s02
    s03
    s02
    s03
    Also note you will have to modify the above commands to work with files instead of text.
    ls -1 Your_Photo_Directory | sed s'/_/ /g' | sort -k1,1d -k3,3d -k4,4n | sed 's/ /_/g'
    ls -1 Your_Photo_Directory | grep -Eo '[Ss][[:digit:]]+'
    etc.

  • [SOLVED] sed help please...

    I'm trying to modify an XFWM theme, and need to run sed to replace colors with a phrase to make it "blend in" with the GTK theme. Unfortunately, it isn't working. Can anyone help?
    Here is what I am trying to run:
    sed -e 's/\#E6E6E6/\#E6E6E6 s active_color_2/g' *-active.xpm
    The result of that gives me something similar to running cat *-active.xpm.
    Last edited by smartboyathome (2009-03-25 21:49:53)

    the above should work but i'd script it:
    edit that, the above will work and will work better, faster and more efficiently...
    but i'd still script it
    #!/bin/bash
    find ./ -name '*-active.xpm' | while read file; do
    cp $file $file.orig
    cat $file | sed 's/\#E6E6E6/\#E6E6E6 s active_color_2/g' > temp
    mv temp $file
    done
    Last edited by brisbin33 (2009-03-25 21:39:20)

  • Sed help / extracting useful bits from a line with sed

    I need to parse some log files extracting only the numerical parts of interest.  Example line:
    x264 [info]: SSIM Mean Y:0.9689320 (15.077db)
    Two goals here:
    1) Capture the number after the "Y:" --> 0.9689320
    2) Capture the number in () without the db --> 15.077
    I thought I'd attack it using sed to find anything up to Y: and delete it, then anything after a space and delete it, but find myself unable to do it.  Suggestions are welcomed.  I can do it with awk/sed combo but want to learn a better way.
    awk '{print $5}' | sed 's/Y://'
    Last edited by graysky (2011-04-10 17:35:21)

    @graysky - As others have said use sed backreferences. Here is an another example.
    sed 's/^.*:\([[:alnum:]]*\.[[:alnum:]]*\) [^\(]*(\(.*\)db)[^\)]*$/\1 \2/'
    Note: disraptor's regex is much easier to read. I'd use it! I just whipped this up before I saw his
    In:
    echo "x264 [info]: SSIM Mean Y:0.9689320 (15.077db)" | sed 's/^.*:\([[:alnum:]]*\.[[:alnum:]]*\) [^\(]*(\(.*\)db)[^\)]*$/\1 \2/'
    Out:
    0.9689320 15.077
    In awk: (One way of doing it!)
    mawk '{gsub(/[Y\:\(\)db]/,""); print $5,$6}'
    In:
    echo "x264 [info]: SSIM Mean Y:0.9689320 (15.077db)" | mawk '{gsub(/[Y\:\(\)db]/,""); print $5,$6}'
    Out:
    0.9689320 15.077
    This was quick but I hope it gets you on the right path
    Edit:
    How about just grep?
    echo $(grep -o '[0-9]\.[0-9]*')
    In:
    echo "x264 [info]: SSIM Mean Y:0.9689320 (15.077db)" | echo $(grep -o '[0-9]\.[0-9]*')
    Out:
    0.9689320 5.077
    Cheap, but I'd thought I would add it anyway!
    P.S. Here is the full way to extract both numbers using awk's substr function as disraptor mentioned before.
    mawk '{print substr($5,3),substr($6,2,6)}'
    Last edited by harryNID (2011-04-11 20:08:31)

  • Grep / sed help please..

    am trying to make a new pkgbuild but the install dirs are coded in the makefile and will not be overridden with DESTDIR or prefix
    in the makefile i have already sed out the references to local, however the variables for bin-prefix, data_prefix and highscore_prefix are on lines 1,2 and three respectively.
    the sed command for removing local was lifted from another pkgbuild
    as i see it there are a few options one is to remove lines 1,2,3 and then move the directories to pkg to be tarred up or to insert pkg into 1,2,3
    i know you can also bind the root of the package but am stumped as to the correct commands, any ideas guys?

    Sorry  :oops:
    here is the pkg build
    pkgname=twind
    pkgver=1.1.0
    pkgrel=1
    pkgdesc="An addictive block game"
    url="http://twind.sourceforge.net"
    depends=('sdl' 'sdl_image' 'sdl_mixer')
    source=(http://dl.sourceforge.net/sourceforge/twind/twind-1.1.0.tar.gz)
    md5sums=('672dfe032e1f5657996b64cd666aef50')
    build() {
    cd $startdir/src/$pkgname-$pkgver
    sed -i -e "s:local/::" Makefile
    make || return 1
    mkdir -p $startdir/pkg/usr
    make prefix=$startdir/pkg install
    but the install command in the makefile will not accept external variable
    here is the makefile...
    # ONLY CHANGE THESE THREE OPTIONS IF YOU KNOW WHAT YOU ARE DOING
    BIN_PREFIX = /usr/bin/
    # if you don't have privileges to install systemwide, comment out both
    # lines below and the game will then play from the current directory
    DATA_PREFIX = /usr/share/games/twind/
    HIGH_SCORE_PREFIX = /var/lib/games/twind/
    # uncomment out the EXTENSION if you don't have the png libs on your system
    #EXTENSION = ".bmp"
    AUDIOFLAG = AUDIO
    CC = gcc
    ifdef EXTENSION
    CFLAGS = -Wall -g -DDATA_PREFIX="$(DATA_PREFIX)"
    -DEXTENSION="$(EXTENSION)" -D$(AUDIOFLAG) -DLINUX
    -DHIGH_SCORE_PREFIX="$(HIGH_SCORE_PREFIX)"
    else
    CFLAGS = -Wall -g -DDATA_PREFIX="$(DATA_PREFIX)" -D$(AUDIOFLAG) -DLINUX
    -DHIGH_SCORE_PREFIX="$(HIGH_SCORE_PREFIX)"
    endif
    LIBS = -lm
    SDL_CFLAGS = `sdl-config --cflags`
    SDL_LIBS = `sdl-config --libs` -lSDL_image
    MIXER_LIB = -lSDL_mixer
    all: twind
    install:
    mkdir -p $(DATA_PREFIX)graphics
    mkdir -p $(DATA_PREFIX)music
    mkdir -p $(DATA_PREFIX)sound
    mkdir -p $(HIGH_SCORE_PREFIX)
    ifdef EXTENSION
    cp -r graphics/*.bmp $(DATA_PREFIX)graphics
    else
    cp -r graphics/*.png $(DATA_PREFIX)graphics
    endif
    cp -r music/*.ogg $(DATA_PREFIX)music
    cp -r sound/*.wav $(DATA_PREFIX)sound
    cp twind $(BIN_PREFIX)
    chown root:games $(BIN_PREFIX)twind
    chmod g+s $(BIN_PREFIX)twind
    touch $(HIGH_SCORE_PREFIX)twind.hscr
    chown root:games $(HIGH_SCORE_PREFIX)twind.hscr
    chmod 664 $(HIGH_SCORE_PREFIX)twind.hscr
    uninstall:
    rm -rf $(DATA_PREFIX)
    rm -f $(BIN_PREFIX)twind
    noaudio:
    make twind MIXER_LIB= AUDIOFLAG=NOAUDIO
    twind: twind.o
    $(CC) twind.o $(LIBS) $(SDL_LIBS) $(MIXER_LIB) -o twind
    twind.o: twind.c
    $(CC) $(CFLAGS) $(SDL_CFLAGS) -c twind.c
    clean:
    rm -f twind *.o
    as i said from what i can tell i can either remove the variable and get it to build selfcontained and move this to pkg to be compressed
    insert /pkg into the makefile
    or bind the root of the install into $startdir
    is this any clearer
    as i understand it any of these options will put the needed files into pkg for makepkg to compress.

  • [solved] sed help

    i want this  'N;s/\n/ /;P;D;'     to go into a file but when i try it comes out as this  'N;s/ / /;P;D;'
    how can i make the \n copy over, i've tried searching but no luck.
    Last edited by moofly (2012-09-03 04:12:25)

    input
    comm -13 '\''/home/ryan/Computer Backup/main/main programs'\'' '\''/home/ryan/Computer Backup/backup/backup programs'\'' | sed '\''1isudo pacman -Runs'\''| sed '\''N;s/\n/ /;P;D;'\'' | sed '\''N;s/\n/ /;P;D;'\'' | sed '\''N;s/\n/ /;P;D;'\'' | sed '\''N;s/\n/ /;P;D;'\'' | sed '\''N;s/\n/ /;P;D;'\'' > '\''/home/ryan/Computer Backup/backup/backup remove'\''
    output
    comm -13 '/home/ryan/Computer Backup/main/main programs' '/home/ryan/Computer Backup/backup/backup programs' | sed '1isudo pacman -Runs'| sed 'N;s/\n/ /;P;D;' | sed 'N;s/ / /;P;D;' | sed 'N;s/ / /;P;D;' | sed 'N;s/ / /;P;D;' | sed 'N;s/ / /;P;D;' > '/home/ryan/Computer Backup/backup/backup remove'
    all the
    'N;s/ / /;P;D;'
    in the output are supposed to be
    'N;s/\n/ /;P;D;'
    thats not everything that goes into the file but its the section im having trouble with. Since thats not everything, i don't think echo will work unless i can choose where to put the text. If i can choose where to put the text let me know.
    Last edited by moofly (2012-09-03 03:47:48)

  • Upgpkg: Bumps pkgver of a package, reset pkgrel to 1

    Hi all,
    I'm working on a script which will bump the pkgver of a package
    and reset pkgrel to 1. It also starts the build and reverts
    back to the old version if the build failed. However, I can't
    find out a way to remove the md5sums of the old source,
    so that it can be replaced.
    Here's the current code:
    #!/bin/sh
    PKGDIR="/home/sol/arch/pkgbuilds"
    err() {
    echo $1
    exit 1
    if [ -z $1 ]; then echo "usage: upgpkg package-name newver"; exit; fi
    if [ ! -d "$PKGDIR/$1" ]; then err "upgpkg: package $1 not in $PKGDIR."; fi
    if [ -z $2 ]; then err "upgpkg: no new version specified for $1."; fi
    cd "$PKGDIR/$1"
    . PKGBUILD
    if [ $(vercmp $2 $pkgver) -gt 0 ]; then
    sed -i "s/pkgver=.*$/pkgver=$2/g" PKGBUILD
    sed -i "s/pkgrel=.*$/pkgrel=1/g" PKGBUILD
    else
    err "upgpkg: $1 - new version ($2) older than current $pkgver"
    fi
    makepkg -m
    if [ $? -gt 0 ]; then
    sed -i "s/pkgver=.*$/pkgver=$pkgver/g" PKGBUILD
    sed -i "s/pkgrel=.*$/pkgrel=$pkgrel/g" PKGBUILD
    err "upgpkg: $1 - build failed for $2, reverting to $pkgver"
    fi

    I don't know how to replace the md5sums in place... but the md5sums
    can be deleted and then regenerated by makepkg -g (even for
    md5sums spanning multiple lines).
    Anyway, here goes the upgpkg code. I've modified a bit to work nicely
    with pkgtools, but it can be easily changed to make it standalone if
    the user wants.
    #!/bin/bash
    # upgpkg: Upgrades package versions in PKGBUILD and starts build.
    # Author: Abhishek Dasgupta <[email protected]>
    # Thanks to cactus, profjim and daenyth for all the sed help!
    # Requires: pkgtools.
    # I place this script in the public domain.
    MYVERSION=0.1
    PROGNAME="upgpkg"
    if [ -r /usr/share/pkgtools/functions ]; then
    source /usr/share/pkgtools/functions
    else
    printf "$(gettext "upgpkg: Unable to source function file!\n")" >&2
    exit 1
    fi
    die() {
    local message="$1"
    shift
    printf "$message" "$@"
    exit 1
    if [ -r /etc/pkgtools/newpkg.conf ]; then
    source /etc/pkgtools/newpkg.conf
    fi
    if [ -r "${HOME}/.pkgtools/newpkg.conf" ]; then
    source "${HOME}/.pkgtools/newpkg.conf"
    fi
    if [ -z $BASEDIR ]; then die "$(gettext "upgpkg: unable to locate BASEDIR in configuration.")"; fi
    if [ -z $1 ]; then printf "upgpkg %s\n" "$MYVERSION"; printf "$(gettext "usage: upgpkg package-name newver\n")"; exit; fi
    if [ ! -d "$BASEDIR/$1" ]; then die "$(gettext "upgpkg: package %s not in %s.\n")" "$1" "$BASEDIR"; fi
    if [ -z $2 ]; then die "$(gettext "upgpkg: no new version specified for %s\n")" "$1"; fi
    # Main code follows
    cd "$BASEDIR/$1"
    sed -ri '/md5sums[ ]?\=/{:a; /\)/d; N; ba;}' PKGBUILD || die "upgpkg: could not bump pkgver of $1\n"
    source PKGBUILD
    if [ $(vercmp $2 $pkgver) -gt 0 ]; then
    sed -i "s/pkgver=.*$/pkgver=$2/g" PKGBUILD
    sed -i "s/pkgrel=.*$/pkgrel=1/g" PKGBUILD
    makepkg -g >> PKGBUILD
    else
    die "$(gettext "upgpkg: %s - new version (%s) older or equal to current %s\n")" "$1" "$2" "$pkgver"
    fi
    makepkg -m
    if [ $? -gt 0 ]; then
    sed -i "s/pkgver=.*$/pkgver=$pkgver/g" PKGBUILD
    sed -i "s/pkgrel=.*$/pkgrel=$pkgrel/g" PKGBUILD
    die "$(gettext "upgpkg: %s - build failed for %s, reverting to %s\n")" "$1" "$2" "$pkgver"
    fi

  • HT4539 All my old tv shows are not working please help my computer sed I have to Atheris 5 computers to play all my old tv shows I Pade for with eney Itunas cards. :( :'(

    All my old tv shows are not working please help my computer sed I have to Atheris 5 computers to play all my old tv shows I Pade for with eney Itunas cards.

    What do y mean by not work?
    What happens when y try to play them on yur iPod?
    What happens when yo try to play them in iTunes on yur computer?
    If you get a message what is the exact wording of the message?
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    Some countries do not allow redownloads some kinds of media

  • Help needed extracting information from command output using sed

    I want to be able to pipe the output of:
    playerctl metadata
    into sed and extract only the relevant information. I have a working knowledge of regular expressions but I'm not how to get sed to only output the matched text. For reference, this is an example output of the playerctl command:
    {'mpris:artUrl': <'http://open.spotify.com/thumb/ddf652a13affe3346b8f65b3a92bd3abfdbf7eca'>, 'mpris:length': <uint64 290000000>, 'mpris:trackid': <'spotify:track:0xqi1uFFyefvTWy0AEQDJ7'>, 'xesam:album': <"Smokey's Haunt">, 'xesam:artist': <['Urthboy']>, 'xesam:autoRating': <0.23000000000000001>, 'xesam:contentCreated': <'2012-01-01T00:00:00'>, 'xesam:discNumber': <1>, 'xesam:title': <'On Your Shoulders'>, 'xesam:trackNumber': <6>, 'xesam:url': <'spotify:track:0xqi1uFFyefvTWy0AEQDJ7'>}%
    I'm trying to get the track name and artist name and combine them into one string. Perhaps sed isn't the tool for the job but I'm not really sure what else to try. Any help is very appreciated.

    If that was valid json, which it doesn't appear to be, you could use jshon to query it.
    Are you sure that is the exact output of the command? It looks sort of off...
    In the meatime, this is pretty hacky:
    awk 'BEGIN { RS=","; FS="'\''" }; /artist/ { artist = $4 }; /title/ { title = $4 } END { print artist": "title }' file
    Urthboy: On Your Shoulders

  • Need help with sed to fix migrated web site links (part II)

    I thought I had this fixed, but I didn't, so starting over:
    I'm moving my web files from one host to another, and have backed up my directory called WEB into my user downloads folder.  The site is dead simple, mostly links within the site, pages primarily text with some links to my photos posted on flickr, and a few outside links.  I want to avoid opening/replacing/saving a hundred or more files to fix the links from "http://www.old_domain_name/user/my_username" to "http://my_new_domain_name"
    A friend suggested the following scripts to do this
      mkdir fix_urls
      cd fix_urls
      cp -r <wherever>/WEB .
      cd WEB
      xargs -0 egrep -i  old_domain_name $(find * -name "*.html" -print0) > ../to_fix
      cd ..
      less to_fix
    to see what needs changing, but after I've created and moved to WEB, the xargs command results in a zero kb file called to_fix appearing in WEB, and nothing else happens....and the prompt in terminal (myusername$) doesn't reappear.
    I tried his part II anyway:
      mkdir new_web
      while read filename; do
          sed 's/\/www.old_domain_name/user/my_username/\/my_new_domain_name/' < WEB/$filename > new_web/$filename
      done
      diff -r WEB new_web > what_i_did
      less what_i_did
    and after the 'done', I get again....nothing.  No new cursor gray rectangle, no new prompt, haven't even gotten to the last bit of diff to review the changes.
    Any tips on what fundamental bone-headed thing I'm doing wrong?
    and I got this helpful answer which seemed to have solved it, but didn't entirely:
    This solved my question by X423424X  on Jul 1, 2012 1:23 AM
    I want to avoid opening/replacing/saving a hundred or more files to fix the links from "http://www.old_domain_name/user/my_username" to "http://my_new_domain_name"
    If that's all you want to do then here's the pertinent sed command to do it:
    sed -e 's,www.old_domain_name/user/my_username,my_new_domain_name,'
    Syntax is a bit simpler when you don't use slashes as the sed substitute delimiters.  You can use anything.  Here I used commas.
    I got excited too quickly after the first file I clicked looked correct--the first file in the subdirectory.
    I see no indication in terminal that the process is going or ending--no sense of when I can close terminal and move on.
    Checking the directory in finder shows no updates to 'date modified' for any of the files.
    So how do I know if it is in progress, or done working, aside from opening random files to see if they're 'done'?
    I've got three subfolders inside one folder (my WEB folder), and it looks like only the first file of the first subdirectory got repaired.

    Here is a bash script to interate through all files in a folder of a given extension.
    #!/bin/bash
    # be sure to use Unix lineends -- linefeed \n
    # Use TextWrangle for editing.  It's free.
    # http://www.barebones.com/products/TextWrangler/
    # or nano in the terminal
    # to make this file -- listFile.bash runable do:
    # chmod u+x listFile.bash
    # debug info
    export PS4='+(${BASH_SOURCE}:${LINENO}):'
    # remove the leading # in the line below to show debug info
    # set -o xtrace
    # first comes the directory/folder you want to search
    # -name do a case independent search for all file ending
    #       with the extension .txt
    find /Users/mac/Desktop/iMac -iname "*.txt" | while read file
    do
        echo
        echo "file to process is = " $file
        # replace the list command with your command.
        # You will need to place a $ in front of file
        # To avoid problems with blanks & other characters,
        # put " around $file, your variable.
        ls -l "$file"
    done
    mac $ chmod u+x /Users/mac/Desktop/listFiles.bash
    mac $ /Users/mac/Desktop/listFiles.bash
    file to process is =  /Users/mac/Desktop/iMac/bash/pdisk-l.txt
    -rw-r--r--   1 mac  staff  20915 Feb  4  2009 /Users/mac/Desktop/iMac/bash/pdisk-l.txt
    file to process is =  /Users/mac/Desktop/iMac/comments on new forum software.txt
    -rw-r--r--   1 mac  staff  1966 May 26  2011 /Users/mac/Desktop/iMac/comments on new forum software.txt
    file to process is =  /Users/mac/Desktop/iMac/hidden mac os files.txt
    -rw-r--r--   1 mac  staff  1499 Jul  1 17:01 /Users/mac/Desktop/iMac/hidden mac os files.txt
    file to process is =  /Users/mac/Desktop/iMac/key combinations.txt
    -rw-r--r--   1 mac  staff  2547 Aug 24  2011 /Users/mac/Desktop/iMac/key combinations.txt
    file to process is =  /Users/mac/Desktop/iMac/nvram -p.txt
    -rw-r--r--   1 mac  staff  1248 Feb  1  2011 /Users/mac/Desktop/iMac/nvram -p.txt
    file to process is =  /Users/mac/Desktop/iMac/reset mac Open Firmware.txt
    -rw-r--r--   1 mac  staff  7876 Jun 25 21:56 /Users/mac/Desktop/iMac/reset mac Open Firmware.txt
    mac $

  • Help with sed in a PKGBUILD

    Basically, I need to make a few modifications to a conf file but I am no good with sed.  Here is a portion of the original conf file:
    our %HTTP_LOG = ("Linux-RHFC" => "/var/log/httpd/access_log",
    "Linux-Debian" => "/var/log/apache2/access.log",
    "Linux-Gentoo" => "/var/log/apache2/access_log",
    "Linux-Slack" => "/var/log/httpd/access.log",
    "Linux-SuSE" => "/var/log/apache2/access_log",
    "Linux-Generic" => "/var/log/httpd/access_log",
    "FreeBSD" => "/var/log/httpd-access.log");
    our %BASE_WWW = ("Linux-RHFC" => "/var/www/html",
    "Linux-Debian" => "/var/www",
    "Linux-Gentoo" => "/var/www/localhost/htdocs",
    "Linux-Slack" => "/var/www/htdocs",
    "Linux-SuSE" => "/srv/www/htdocs",
    "Linux-Generic" => "/usr/local/www",
    "FreeBSD" => "/usr/local/www/apache22/data");
    I need to make two changes:
    1) change the .log to _log in the following:
    "Linux-Slack"   => "/var/log/httpd/access.log",
    2) change the path from "/var/www/htdocs" to "/srv/http" in the following:
    "Linux-Slack"   => "/var/www/htdocs",
    Here is a model line with sed making another needed change that res wrote into the PKGBUILD:
    sed '/^our $OSTYPE = "Linux-RHFC"/ s,RHFC,Slack,' < $pkgname.conf \
    > $pkgdir/etc/$pkgname.conf
    Basically, I can't adapt his line to do what I need.  Anyone willing to help me out?  BTW, this is for the monitorix PKGBUILD in the AUR: http://aur.archlinux.org/packages.php?ID=33911
    Last edited by graysky (2010-01-26 21:35:28)

    CommandLine: (Combined)
    sed '/ *"Linux-Slack"/{ s=/var/www=/srv/http=; s=log=_log= }' < infile > outfile
    Output:
    our %HTTP_LOG = ("Linux-RHFC"   => "/var/log/httpd/access_log",
                    "Linux-Debian"  => "/var/log/apache2/access.log",
                    "Linux-Gentoo"  => "/var/log/apache2/access_log",
                    "Linux-Slack"   => "/var/_log/httpd/access.log",
                    "Linux-SuSE"    => "/var/log/apache2/access_log",
                    "Linux-Generic" => "/var/log/httpd/access_log",
                    "FreeBSD"       => "/var/log/httpd-access.log");
    our %BASE_WWW = ("Linux-RHFC"   => "/var/www/html",
                    "Linux-Debian"  => "/var/www",
                    "Linux-Gentoo"  => "/var/www/localhost/htdocs",
                    "Linux-Slack"   => "/srv/http/htdocs",
                    "Linux-SuSE"    => "/srv/www/htdocs",
                    "Linux-Generic" => "/usr/local/www",
                    "FreeBSD"       => "/usr/local/www/apache22/data");
    Don't try to write to the original file using this approach as it will clobber your original file. Use "sed -i" to save to the original file instead. The "< infile > outfile" save the output to another file obviously.
    Sed Script: ( Invoked as sed -f whatever_you_call_the_script file )
    / *"Linux-Slack"/{
    s=/var/www=/srv/http=
    s=log=_log=
    sed '/^our $OSTYPE = "Linux-RHFC"/ s,RHFC,Slack,' < $pkgname.conf \
                                                        > $pkgdir/etc/$pkgname.conf
    This means find this regex pattern ^our $OSTYPE = "Linux-RHFC" and whatever it matches change RHFC to Slack. Take $pkgname.conf as the infile and send the output of sed to $pkgdir/etc/$pkgname.conf
    Notice he used s,RHFC,Slack, and I used s=log=_log=. This is typically done if you have a lot of "/" in a file. Sed's typical replacement pattern is this s/original/changed/ but as I mentioned it becomes hard to figure out if you have something like this s/\/mnt\/usb\/somefile/\/mnt\/usb\/somename/. Sed allows you to substitute any character (except a few special ones) in place of "/" in it's replacement pattern as long as you follow through the whole command like that. So in essence these are equivalent s,RHFC,Slack,, s=RHFC=Slack=, s/RHFC/Slack/
    You did say you wanted to know. Hope this is what you were looking for or at least a step in the right direction. Sorry if I bored you with the school lession.

  • Text manipulation with tr or sed or ... help needed ...

    Dear All,
    I need to get the following ...:
    HELP\nME ==> remove \n
    HELP \nME ==> do nothing
    HELP\n ME ==> do nothing
    HELP \n ME ==> do nothing
    I know that I can easily remove all '\n' with "tr -d '\n' <infile.txt >outfile.txt", but this is a little different ;-)
    Best, and thanks in advance, Peter

    If this what you need:
    [kido@kido ~]$ cat help.txt
    HELP\nME
    HELP \nME
    HELP\n ME
    HELP \n ME
    [kido@kido ~]$ sed 's/HELP\\nME/HELP ME/g' help.txt
    HELP ME
    HELP \nME
    HELP\n ME
    HELP \n ME
    OK, seems like the portal has serious text formatting issues.
    Let me put the command this way:
    $ sed 's/HELP_backslash_backslash_n_ME/HELP ME/g' help,txt
    Replace "backslash" word with the corresponding sign; Please not that between HELP, backslash and backslash there are no free spaces; I used "_" just to mark the boundaries..
    Regards,
    kido
    Edited by: kido on Jul 30, 2009 10:05 AM

  • [Solved]Sed pattern matching help

    Ok I have a file like:
    foo
    cloo
    zoo
    And I want to have a script where: If it finds a line "foo" in a file, I want it to change the file to be:
    foo bar
    cloo
    zoo
    However, if the file already has "bar" appended to the line (as per the second example above), I want it to ignore the line.
    A sed line:
    sed -i '/foo/ s/$/ bar/' ~/myfile
    Will do the trick as far as appending " bar" to lines that say "foo"
    but it will also append " bar" to lines that already say "foo bar"
    What I need is code that will look for lines that say "foo" and append the " bar", but ignore instances where the " bar" has already been appended.
    In English: Find lines that start with "foo" but do not include " bar" and append bar to the end of the line.
    I am not married to using sed, but it needs to be something I can toss into a bash script and run.  This seems simple, but hours later...
    Thanks
    Last edited by andrekp (2013-10-03 19:31:53)

    Thanks for ALL of your help, everyone.  Works great.
    Just to show what I was REALLY doing, I run openbox with obmenu-generator and I was trying to have a special menu entry for certain programs that I use a lot so that I could find them easily and immediately.  This entailed creating a special category for the program in the respective /usr/share/applications/<program>.desktop file on the "Categories=" line.
    A typical line might read:
    Categories=GNOME;GTK;Office;Viewer;Graphics;2DGraphics;VectorGraphics;
    And I wanted to add my special category, "Favorites" at the end.  Leaving out lots of detail, this would allow me to have a special menu item for certain programs.  At first I just added it manually like:
    Categories=GNOME;GTK;Office;Viewer;Graphics;2DGraphics;VectorGraphics;Favorites
    but I found that the <program>.desktop file would get replaced on updates and overwrite my changes every so often.  So I figured I'd write a script to do the updating and just run that when I saw the need.
    And additional wrinkle was that some programs had the line by default as:
    Categories=GNOME;GTK;Office;Viewer;Graphics;2DGraphics;VectorGraphics;
    and others as:
    Categories=GNOME;GTK;Office;Viewer;Graphics;2DGraphics;VectorGraphics
    Note the final ; or lack thereof, so I had to account for that as well.  (Actually, I could ignore it and just add ;Favorites to the end, since the system ignored ";;" as being an error - but I wanted to do it cleanly.)
    My final code became:
    sudo sed -i 's/\(Categories.*\);$/\1/;/Favorites/! s/Categories.*$/&;Favorites/' /usr/share/applications/evince.desktop
    which first strips off the final ; if found on the Categories line, then adds ;Favorites to the end of that line.  I just created a line in a bash script for each program I wanted to form the favorites menu, as above.  Works well.  May or may not be the best way, but...
    Anyway, maybe this will give an idea helpful to someone else.   
    (Personally, I think it would be nice if the .desktop files, which are really just configuration files, should warn you when they overwrite, but that's probably a losing argument.)
    Thanks again,
    Andre

  • Sed script help

    Hi, I could use your help..
    The problem: I've got an m3u playlist with some of my favorite tracks. The files reside in album folders, which follow a naming scheme, but that has changed so I have to update all the references. What I have in mind is to use sed for extracting the mp3 filename, then somehow find the new path to that file and substitute it for the old one. I've managed to crawl this far, but obviously it won't work:
    cat ultimate.m3u | sed -e 's/.*\///g' | sed -e 's/\(.*\.mp3')/`find -name \1`/g
    please show me some geekism, regards
    flo

    cannot reproduce...
    //blue/0/~ cat ./test.m3u
    G2/G2-G2010-2003-Bad_MF/01-bad-mf-cosmois.mp3
    720_Degrees/720_Degrees-720NU016-Blame-2004/01-blame-desert_planet.mp3
    Virus-Various_Artists-VRS009-Life_Story_Vol_1-2001/02-cause_4_concern-peep_show.mp3
    1210/1210-1210-006-Crossfire-2003/01-crossfire_-_hideout.mp3
    Violence/Violence-Gridlok-2003-VIO006/02-gridlok-aggressor.mp3
    //blue/0/~ while read old_path; do
    // file=$(basename $old_path)
    // echo file is $file
    // echo "i would be finding ./ -name '$file' right now..."
    // done < ./test.m3u
    file is 01-bad-mf-cosmois.mp3
    i would be finding ./ -name '01-bad-mf-cosmois.mp3' right now...
    file is 01-blame-desert_planet.mp3
    i would be finding ./ -name '01-blame-desert_planet.mp3' right now...
    file is 02-cause_4_concern-peep_show.mp3
    i would be finding ./ -name '02-cause_4_concern-peep_show.mp3' right now...
    file is 01-crossfire_-_hideout.mp3
    i would be finding ./ -name '01-crossfire_-_hideout.mp3' right now...
    file is 02-gridlok-aggressor.mp3
    i would be finding ./ -name '02-gridlok-aggressor.mp3' right now...
    seems to be working here.  perhaps your not looking in the right directory with your find command? ~/Music was just my example.

  • [SOLVED] Need Help with Sed

    Since I'm a dirty TF2 idler and I use Source Tools to idle, it uses a list of servers from a servers.txt file.
    A list of idling servers is here: http://tf2stats.net/blacklist_generate/ … ourcetools
    The list is in this format:
    {IP ADDRESS}:{PORT};{SERVER NAME}
    Unfortunately, I can't just save that as the list, because it thinks you're trying to send {SERVER NAME} as a command or something.
    There's ~920 lines that are just that and so I need to remove everything AFTER the port number (so it would be the colon and the server name).
    The tricky part is that not all ports are the same. 27015 is the standard, some use 27016, and some use other ones. So I need to have a sed command to remove everything past a colon on all lines, then remove the colon on all lines.
    And since I suck at sed, I've come crawling to the forums for help. So please, help.
    Last edited by Arm-the-Homeless (2010-04-05 23:47:19)

    Procyon wrote:@brisbin33: if you're going to redefine IFS, why not to :; with while read ip port name
    true story.  IFS=$'\n'; while read -r is just a habit i fall back on when i want to read [possibly inconsistent] lines out of a file.

Maybe you are looking for

  • BAPI_PR_CREATE for Service line items only

    Hi All, We are unable to create the Purchase Requistion Order using the BAPI_PR_CREATE for Service line items. The Error Message 436(06) " In case of account assignment, please enter acc. assignment data for item" is always received with respect to A

  • I am unable to download iTunes (10.5.2).

    I am unable to download iTunes (10.5.2). When I attempt to download I get an error message which reads: "Apple Software Update Errors occured while installing the updates. If the problem persists, choose Tools>Download Only and try installing manuall

  • Attach Documents to Custom Program Using Generic Object Services

    Hi There,          I created Object type ZGOS and used in the custom program, when i try to attach documents it allows and then shows in attachment list.         But When I use that program next time that document attached is not available. Is there

  • How to display an expanded hierarchy in report?

    Hi, i'm working with BI 7.0. How do I display a completly expanded Hierarchy in my report. At present I see the hierarchy but the nodes need to be manually expanded in the report. pls help, SD

  • Startup upgrade ORA-00205: error in identifying control file

    Hi, I am doing a manual upgrade from 10.2.04 to 11.2.03. I have installed 11.2.0.3. Ran utlu112i.sql Copied TNSNAMES and LISTENER.ora,init.ora from 10g home to 11g home respective directories. Commented all dump_dest paramteres in 11g init.ora and ad