pls. help with appening a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers pls. help with appening a file
# 1  
Old 07-02-2009
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 07:03 PM.. Reason: code tags, PLEASE!
# 2  
Old 07-02-2009
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  
Old 07-02-2009
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  
Old 07-02-2009
Quote:
Originally Posted by samnyc
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  
Old 07-06-2009
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  
Old 07-06-2009
Quote:
Originally Posted by samnyc
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 Smilie.
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pls. help with sudoers file...

Hi, I was asked to create sudoers file for operation team so they can sudo as another user and run few commands. I have updated /etc/sudoers file. User_Alias LEVEL1 = JamesF, dennisW, juanC, steveS, Cmnd_Alias SU_PROD=/bin/su prod, /bin/su - prod Cmnd_Alias SU_NYOP=/bin/su... (2 Replies)
Discussion started by: samnyc
2 Replies

2. UNIX for Dummies Questions & Answers

pls help, file name with brackets

Hi all, I have a number files like these below R1_970804_125318 R1_970804_125404(2) R1_980322_219282 R1_980301_210651(2) R1_980301_210651(3)and I'm trying to put file names into a string in order to perform some processings. FILES=`cat namelist.txt` for F in $FILES do ... ...... (10 Replies)
Discussion started by: sunnydanniel
10 Replies

3. Shell Programming and Scripting

Need Help with greping two line from a file Pls help ASAP

Hi all - I''m in a little bit of jam - If you can please help I have a file that has the following content ( please see below) I need to read the file and then get this result in this format ------------- To put out in this format name: sophis Total: 22328 name: tca ... (2 Replies)
Discussion started by: mnassiri
2 Replies

4. Shell Programming and Scripting

use awk to edit a file..pls help

hey i want to over write the fourth field of a ':' delimited file by first finding the required row by using grep. i have done the following cat file | grep no. | awk -F ':' { $4=count; print $1:$2:$3:$4;} the correct values are being printed but nothin is bein added to the file..please... (5 Replies)
Discussion started by: dhe.arora
5 Replies

5. UNIX for Dummies Questions & Answers

Pls help me with file editing using awk

Hi all, Pls help me with file editing using awk. I have a text file with the below format. "STANDARD VOLUME ","2009","BUX","V","JCBH49","NF", 001413 "VENDOR MATERIAL-STD ","2009","BUX","V","JCBH49","NF", 009948 "INBOUND TRANS-STD ... (2 Replies)
Discussion started by: srinivas.maddy
2 Replies

6. Shell Programming and Scripting

To Change the file format Pls Help!!!

Hi All, I have a file like john::208:johnson john::208:mery john::208:test admin:*:1:johnson admin:*:1:test and wanna convert this as john::208:johnson,mery,test admin:*:1:johnson,test please help me to create a script for this thanks in advance John (4 Replies)
Discussion started by: johnsonpk
4 Replies

7. Shell Programming and Scripting

compare 2 file and print difference in the third file URG PLS

Hi I have two files in unix. I need to compare two files and print the differed lines in other file Eg file1 1111 2222 3333 file2 1111 2222 3333 4444 5555 newfile 4444 5555 Thanks In advance (3 Replies)
Discussion started by: evvander
3 Replies

8. UNIX for Dummies Questions & Answers

Pls help : file stamp issue on HP UX Servers

Hi All , I have a file which gets updated by a korn job daily . The file gets the latest timestamp on everyrun. But of late i have observed that the file timestamp gets modified to a older date ( Oct 25 2006 ) at some point in time of the day. This change has nothing to do with the job which... (2 Replies)
Discussion started by: siddaonline
2 Replies

9. Programming

File I/O ERRORS.. PLS HELP..

Hi people, I am having a little problem with my client side of the concurrent programming, i have a makefile, serverside and clientside directories. makefile works well with serverside files. and now when i added the clientside files to the makefile and compiled... it gives me the follwong error.... (0 Replies)
Discussion started by: SwetaShah
0 Replies

10. Shell Programming and Scripting

Passing value from shell script to .pls file

I have a shell script which takes at the command prompt options like ss1.sh -F SCOTT -T JOHN F- From User T- To User I want to pass the From User(SCOTT) Value to another script ss2.pls (This script runs a PL/SQL Program). Depending on the FromUser value in the ss1.sh script i have to... (4 Replies)
Discussion started by: dreams5617
4 Replies
Login or Register to Ask a Question