![]() |
#1 |
Developer's Corner Mascot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
|
Manipulate "My Clippings" through command line
I've found this nice script to export from a file all the text between two word/string:
Code:
sed '/WORD1 a /!d;s//&\n/;s/.*\n//;:a;/WORD2/bb;$!{n;ba};:b;s//\n&/;P;D' inputfile.txt > output.txt Code:
sed: can't find label for jump to 'a}' Does anybody know why on kindle it doesn't works as it does on linux? Or another script to do the same task? I've searched a lot through sed / awk forums but can't find nothing other than this... |
![]() |
![]() |
![]() |
#2 |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
It is Busybox sed
try: Code:
busybox sed '/WORD1 a /!d;s//&\n/;s/.*\n//;:a;/WORD2/bb;$!{n;ba};:b;s//\n&/;P;D' inputfile.txt > output.txt The same **version** of busybox as used on the <pick model here> kindle. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Developer's Corner Mascot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
|
Same error
![]() |
![]() |
![]() |
![]() |
#4 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
can provide full sed. if required.
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Developer's Corner Mascot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
|
It seems to be a condensed script, not a simple sed command.. dunno if the issue depends on sed or on the rest of the syntax mmh... too condensed to be deciphered, for me at least xD
Last edited by Aeris; 10-17-2013 at 12:57 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
or a newer busybox might do the trick I suppose
|
![]() |
![]() |
![]() |
#7 |
Developer's Corner Mascot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
|
It's incredible, on the net you can't find any command to accomplish this simple task neither in awk, sed or grep, other than this one
|
![]() |
![]() |
![]() |
#8 | |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
start by editing that monster into multiple lines, a program statement per line. |
|
![]() |
![]() |
![]() |
#9 |
Developer's Corner Mascot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
|
Like this?:
Code:
/WORD1 a /!d; s//&\n/; s/.*\n//; :a; /WORD2/bb; $!{n; ba}; :b; s//\n&/; P; D |
![]() |
![]() |
![]() |
#10 |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
|
![]() |
![]() |
![]() |
#11 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
[root@kindle root]# /mnt/us/extensions/sed/usr/bin/sed \
'/WORD1 a /!d;s//&\n/;s/.*\n//;:a;/WORD2/bb;$!{n;ba};:b;s//\n&/;P;D' \ /mnt/us/documents/galc.txt > \ /mnt/us/documents/galc-sed.txt works perfectly. |
![]() |
![]() |
![]() |
#12 |
Developer's Corner Mascot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
|
I solved running this command:
Code:
sed 's/\(WORD1\|WORD2\)/\n&\n/g' "/mnt/us/documents/My Clippings.txt" | awk '/WORD2/{p=0;printf s;s=""}p{s=s$0"\n"};/WORD1/{p=1}' > "/mnt/us/documents/output.txt" |
![]() |
![]() |
![]() |
#13 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
|
![]() |
![]() |
![]() |
#14 |
Developer's Corner Mascot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486
Karma: 1277790
Join Date: Sep 2013
Device: Kindle Paperwhite 5.3.4, Kindle Keyboard 3.4
|
Twobob: so it was a busybox sed issue?
|
![]() |
![]() |
![]() |
#15 |
(offline)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,907
Karma: 6736094
Join Date: Dec 2011
Device: K3, K4, K5, KPW, KPW2
|
Yes. Busybox is a single "all-in-one executable" which implements many of the standard GNU commands.* But for some, it only supports a limited subset of the full-blown executable's functionality.
http://www.busybox.net/about.html (*) You will find that on most embedded devices, all these executables are either symlinked or hardlinked to the (single) busybox executable. IIRC, the Kindle uses hard links. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fetched new per command line are not "marked" as news | tetanos | Library Management | 2 | 04-26-2013 01:23 AM |
How to categorise a book as "News" from command-line | cptnemo | Recipes | 1 | 04-19-2013 03:46 AM |
"Remove the dependency on the zip command line tool when developing plugins"? | JimmXinu | Plugins | 2 | 07-13-2012 02:09 PM |
Defining Metadata with "calibredb add" command line function. | macr0t0r | Calibre | 3 | 03-01-2012 07:36 PM |
iLiad "joe" command line text editor | bobj | iRex Developer's Corner | 3 | 06-02-2008 03:03 PM |