Question about Shell Script (#!/bin/sh)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

#76 Post by phat7 »

I look at the topic and I look at your question and I see no connection whatsoever.

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#77 Post by recobayu »

I'm sorry Phat7, :cry:
I just ask a question how to grep line between <Menu label> and </Menu> part by part.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#78 Post 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

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#79 Post 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

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#80 Post 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.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#81 Post 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:

Post Reply