Posted: Wed 21 Oct 2015, 06:24
I look at the topic and I look at your question and I see no connection whatsoever.
READ-ONLY Archive
https://oldforum.puppylinux.com/
Not very fast, not very elegant, but something like this should do:recobayu wrote:How to print the submain and save it into separate files based on the main name?
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
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
I am always very impressed by people who can use sed grep and awk, but the truth is this can only be read by Daleksrecobayu wrote:sed -e '/"'${a[$i]}'"/,/"'${a[$((i+1))]}'"/!d' root/.jwmrc|grep "Program label"|cut -d '"' -f2>"$i${a[$i]}.txt"
done
What makes you think that it works?recobayu wrote:I still learning your code now. How come it works?