Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 12 Nov 2019, 01:19
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Question about Shell Script (#!/bin/sh)
Post new topic   Reply to topic View previous topic :: View next topic
Page 6 of 6 [81 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6
Author Message
phat7

Joined: 05 Jun 2015
Posts: 161

PostPosted: Wed 21 Oct 2015, 02:24    Post subject:  

I look at the topic and I look at your question and I see no connection whatsoever.
Back to top
View user's profile Send private message 
recobayu


Joined: 15 Sep 2010
Posts: 365
Location: indonesia

PostPosted: Wed 21 Oct 2015, 23:37    Post subject:  

I'm sorry Phat7, Crying or Very sad
I just ask a question how to grep line between <Menu label> and </Menu> part by part.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1925
Location: Japan

PostPosted: Wed 21 Oct 2015, 23:45    Post subject:  

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:
#!/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
Back to top
View user's profile Send private message 
recobayu


Joined: 15 Sep 2010
Posts: 365
Location: indonesia

PostPosted: Thu 22 Oct 2015, 02:37    Post subject:  

Great! Thanks Mochi.. I still learning your code now. How come it works?

Edit:
This is my script. And it's also works! Very Happy
Code:

#!/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
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5623
Location: Republic of Novo Zelande

PostPosted: Thu 22 Oct 2015, 04:28    Post subject:  

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
Smile

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.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1925
Location: Japan

PostPosted: Fri 23 Oct 2015, 04:01    Post subject:  

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
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 6 of 6 [81 Posts]   Goto page: Previous 1, 2, 3, 4, 5, 6
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0564s ][ Queries: 12 (0.0259s) ][ GZIP on ]