Page 4 of 5

Posted: Wed 21 Oct 2015, 06:24
by phat7
I look at the topic and I look at your question and I see no connection whatsoever.

Posted: Thu 22 Oct 2015, 03:37
by recobayu
I'm sorry Phat7, :cry:
I just ask a question how to grep line between <Menu label> and </Menu> part by part.

Posted: Thu 22 Oct 2015, 03:45
by MochiMoppel
recobayu wrote:How to print the submain and save it into separate files based on the main name?
Not very fast, not very elegant, but something like this should do:

Code: Select all

#!/bin/bash
OUTPUTDIR=/tmp/menutest
[ -d "$OUTPUTDIR" ] && rm "$OUTPUTDIR"/* || mkdir "$OUTPUTDIR"

while read line;do
C=$(echo -n $line |grep '<Menu label'    | cut -d" -f2)
I=$(echo -n $line |grep '<Program label' | cut -d" -f2)
[ "$C" ] && CATEGORY="$C"
[ "$I" ] && MENUITEM="$I" && echo "$MENUITEM" >> "$OUTPUTDIR/$CATEGORY".txt
done < /root/.jwmrc

Posted: Thu 22 Oct 2015, 06:37
by recobayu
Great! Thanks Mochi.. I still learning your code now. How come it works?

Edit:
This is my script. And it's also works! :D

Code: Select all

#!/bin/bash
a=(`grep "<Menu label" /root/.jwmrc|cut -d\" -f2`)

#indeks
for i in ${!a[*]};do
	sed -e '/"'${a[$i]}'"/,/"'${a[$((i+1))]}'"/!d' /root/.jwmrc|grep "Program label"|cut -d '"' -f2>"$i${a[$i]}.txt"
done

Posted: Thu 22 Oct 2015, 08:28
by greengeek
recobayu wrote:sed -e '/"'${a[$i]}'"/,/"'${a[$((i+1))]}'"/!d' root/.jwmrc|grep "Program label"|cut -d '"' -f2>"$i${a[$i]}.txt"
done
I am always very impressed by people who can use sed grep and awk, but the truth is this can only be read by Daleks
:-)

EDIT : somewhere on this forum is a method of playing a file as audio even though it is just scripting text (program from 01micko or technosaurus i think). I will try to find it so I can play this string through it and see what it sounds like.

Posted: Fri 23 Oct 2015, 08:01
by MochiMoppel
recobayu wrote:I still learning your code now. How come it works?
What makes you think that it works?
It's as flawed as your code. Now it's your turn to find the mistake :wink: