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 Wed 26 Nov 2014, 06:24
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Trying to make script to insert file into tmp.txt
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
toowoombalinux

Joined: 15 Feb 2010
Posts: 95

PostPosted: Mon 01 Oct 2012, 23:34    Post_subject:  Trying to make script to insert file into tmp.txt  

G'day,
After trawling through the Internet I've come to a standstill with the following script. And I'm not a scripting guru....
I want to insert the file exit1.tx into the middle of tmp.txt.
Code:
#!/bin/sh
file=tmp.txt
lines=`wc -l $file |awk '{print $1}'`
middle=`expr $lines / 2`
sed -i '${middle}r exit1.txt' tmp.txt

I know that the expressions for lines and middle work however it doesn't want to play ball with sed. If I substitute ${middle} with a number then the sed expression works

exit1.txt has this:
Code:
<icon x="704" y="704" label="Exit User Desktop">/usr/share/Audio-lauchers/desktop/User/exit</icon>

so it's chock full of characters which interfere with sed's syntax.

The answer is probably simple but so am I...

Cheers
Martin
Back to top
View user's profile Send_private_message 
01micko


Joined: 11 Oct 2008
Posts: 7841
Location: qld

PostPosted: Mon 01 Oct 2012, 23:44    Post_subject:  

Try it with double quotes, singles take things as literal.Might work.

Code:
#!/bin/sh
 file=tmp.txt
 lines=`wc -l $file |awk '{print $1}'`
 middle=$(($lines / 2))  #bash math thrown in
 sed -i "${middle}r exit1.txt" tmp.txt


There might even be a better (if speed is an issue) way with a "while read line; do this to $line; done < that" loop

What exactly are you trying to do?

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send_private_message Visit_website 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Tue 02 Oct 2012, 15:59    Post_subject:  

toowoombalinux,

Since placing some xml code in the middle of a file might break up an existing xml sequence, you may find it better to put it following a known line. For instance, if an existing tag in "tmp.txt" ends with </icon> , you could place "exit1.txt" in the line following that tag end by -

Code:
 sed -i '/<\/icon>/r exiit1.txt'  tmp.txt


Cheers,
s
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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