I have read the one-liners many times, unfortunately I still get an error
$cat list
gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 25958 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip
gtk-media-pause | CB60471-06 - Parton, Dolly - Together You And I.zip | 18800 | /home/floris/Muziek/Karaoke/1341838939/CB60471-06 - Parton, Dolly - Together You And I.zip
gtk-media-pause | CB60471-07 - Campbell, Craig - Fish.zip | 22067 | /home/floris/Muziek/Karaoke/1341838939/CB60471-07 - Campbell, Craig - Fish.zip
gtk-media-pause | CB60471-08 - Rimes, LeAnn - Give.zip | 528 | /home/floris/Muziek/Karaoke/1341838939/CB60471-08 - Rimes, LeAnn - Give.zip
$cat script.sh
#!/bin/bash
MUZIEK="22067"
LINES=$(grep -B1 "| $MUZIEK |" list)
NEW_LINES=$(grep -B1 "| $MUZIEK |" list | tac)
sed -i "s?$LINES?$NEW_LINES?g" list
I already use the "?" as the delimiter,
if I run script.sh, sed gives me:
sed: expressie #1, teken 172: onafgemaakte 's'-opdracht
(in English: sed expression #1, character 172: command `s' unfinished)
I think the problem is the newline character in $LINES and $NEW_LINES, but
I hoped that sed was the "ultimate" stream editor and was able to do the trick.
---------- Post updated 25-07-12 at 04:20 PM ---------- Previous update was 24-07-12 at 07:20 PM ----------
can you give me an example in awk?
I tried:
LINES=$(grep -B1 "| $MUZIEK |" "$LIST")
NEW_LINES=$(grep -B1 "| $MUZIEK |" "$LIST" | tac)
awk "{gsub(/$LINES/,$NEW_LINES)} 1" "$LIST">$LIST.bak
uncut output:
++ grep -B1 '| 12890 |' /tmp/karsch/list
+ LINES='gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 7659 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip
gtk-media-pause | CB60471-06 - Parton, Dolly - Together You And I.zip | 12890 | /home/floris/Muziek/Karaoke/1341838939/CB60471-06 - Parton, Dolly - Together You And I.zip'
++ grep -B1 '| 12890 |' /tmp/karsch/list
++ tac
+ NEW_LINES='gtk-media-pause | CB60471-06 - Parton, Dolly - Together You And I.zip | 12890 | /home/floris/Muziek/Karaoke/1341838939/CB60471-06 - Parton, Dolly - Together You And I.zip
gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 7659 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip'
+ awk '{gsub(/gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 7659 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip
gtk-media-pause | CB60471-06 - Parton, Dolly - Together You And I.zip | 12890 | /home/floris/Muziek/Karaoke/1341838939/CB60471-06 - Parton, Dolly - Together You And I.zip/,gtk-media-pause | CB60471-06 - Parton, Dolly - Together You And I.zip | 12890 | /home/floris/Muziek/Karaoke/1341838939/CB60471-06 - Parton, Dolly - Together You And I.zip
gtk-media-pause | CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip | 7659 | /home/floris/Muziek/Karaoke/1341838939/CB60471-05 - Gilbert, Brantley - Country Must Be Country Wide.zip)} 1' /tmp/karsch/list
awk: 1: unexpected character '.'
awk: line 2: syntax error at or near CB60471
awk: line 3: syntax error at or near CB60471
awk: line 3: extra ')'