The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Read a file and search a value in another file create third file using AWK King Kalyan Shell Programming and Scripting 11 06-19-2009 12:05 AM
Need help with awk - how to read a content of a file from every file from file list tanit Shell Programming and Scripting 7 03-10-2009 05:19 AM
file size comparision local file and remote file dba.admin2008 Shell Programming and Scripting 4 11-13-2008 05:57 PM
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 04:38 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 05:25 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2009
samnyc samnyc is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 52
pls. help with appening a file

Hi,

I wrote a script, but it's not working. Please advise. I want to add the text at the end of the file. Should I use sed or awk. Not sure any thing is fine with me.

Code:
#!/usr/bin/ksh
DATE=`/usr/bin/date '+%m%d%y'` 
cp -p /etc/inittab /etc/inittab_$DATE
sed's/$/"hobbit:234:once:/etc/rc.hobbit start"/g' /etc/inittab

Thanks.

Last edited by vgersh99; 07-02-2009 at 06:03 PM.. Reason: code tags, PLEASE!
Bits Awarded / Charged to samnyc for this Post
Date User Comment Amount
07-02-2009 vgersh99 added code tags - charged 10K bits 0
  #2 (permalink)  
Old 07-02-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,121
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
  #3 (permalink)  
Old 07-02-2009
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,974
if you want to add text to the end of a file why not use ">>" to do this?

Code:
echo "hobbit:234:once:/etc/rc.hobbit start" >> /etc/inittab
  #4 (permalink)  
Old 07-02-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
Quote:
Originally Posted by samnyc View Post
Hi,

I wrote a script, but it's not working. Please advise. I want to add the text at the end of the file. Should I use sed or awk. Not sure any thing is fine with me.

Code:
#!/usr/bin/ksh
DATE=`/usr/bin/date '+%m%d%y'` 
cp -p /etc/inittab /etc/inittab_$DATE
sed's/$/"hobbit:234:once:/etc/rc.hobbit start"/g' /etc/inittab

Thanks.
you want to add at the end of the file or the at the end of last line of the file??
  #5 (permalink)  
Old 07-06-2009
samnyc samnyc is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 52
This is what I did and it's working fine but curious to learn if I can do this in a different ways?

Code:
#!/usr/bin/ksh
DATE=`/usr/bin/date '+%m%d%y'` 
cp -p /etc/inittab /etc/inittab_$DATE
cat "hobbit:234:once:/etc/rc.hobbit start"  >>  /etc/inittab
Thanks.
  #6 (permalink)  
Old 07-06-2009
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,974
Quote:
Originally Posted by samnyc View Post
This is what I did and it's working fine but curious to learn if I can do this in a different ways?
as allways there are more than one way to do things in a script. the art is to know which is best for your case .
tools you should look at are maybe sed/ed/awk. but make sure to know the smaller and faster tools like grep/cut/>/>> and so on.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 07:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0