Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-08-2004, 07:57 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
prepend with shell scripting?

is it possible to prepend a file with text in a shell script? the text could be in some other file too.

i may be answering my own question ..
Code:
$ cat > prepend_text.txt > into_file.php > new_file.php
__________________
Mike
sde is offline   Reply With Quote
Old 11-08-2004, 08:16 AM   #2 (permalink)
kaeli69
Registered User
 
kaeli69's Avatar
 
Join Date: Apr 2003
Posts: 30
kaeli69 is an unknown quantity at this point
As far as I know (unix ksh), you have to make a temp file, put the prepend contents in it, append the content of the old file to it, then write the temp file to the old file.

$ cat prependText > tmpFile
$ cat oldFile >> tmpFile
$ cat tmpFile > oldFile

Or however short you can make that if you play with it...
kaeli69 is offline   Reply With Quote
Old 11-08-2004, 08:26 AM   #3 (permalink)
Kernel_Killer
Regular Contributor
 
Kernel_Killer's Avatar
 
Join Date: Feb 2003
Location: indisclosed
Posts: 210
Kernel_Killer is on a distinguished road
Here's a script I wrote awhile ago, that does some prepending that might be useful to you later. It allows you to add text to a file with a newline after each entry. Ignore the dialog part of it, since it really doesn't have too much to do with it.

Code:
#!/bin/sh
DIALOGRC new
dialog --clear
while : [ $menuitem =! 10]
do
dialog --title "ListMuze v0.1.01" --menu "Choose Option" 10 40 4 1 "Add Music" 2 "View List" 3 "Edit List" 10 "Quit" 2>m
enuitem.$$

menuitem=`cat menuitem.$$`
n="\n"
case $menuitem in
   1) dialog --inputbox "Title/Artist" 8 100 2>music.$$ && fmt -w 100 music.$$ >> musiclist;;
   2) dialog --textbox musiclist 25 100;;
   3) vi musiclist;;
   10) `rm -f *.$$`
       exit;;     
   255) echo "exit esc";;
esac
done
__________________
Network Synapse
Screaming Electron
Kernel_Killer is offline   Reply With Quote
Old 11-08-2004, 10:16 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
thanks, i'm all set =)
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell inside webbrowser Hrqls Linux / BSD / OS X 5 04-14-2004 06:41 AM
CLI for noobies: shell programming sde Code Newbie News 0 03-15-2004 12:33 PM
shell script for ftp Hrqls Linux / BSD / OS X 7 09-20-2002 03:14 AM


All times are GMT -8. The time now is 01:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting