Question about Shell Script (#!/bin/sh)
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
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
Great! Thanks Mochi.. I still learning your code now. How come it works?
Edit:
This is my script. And it's also works!
Edit:
This is my script. And it's also works!
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
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.
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan