Need to append the last line of a file on UNIX Box


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to append the last line of a file on UNIX Box
# 1  
Old 05-30-2011
Need to append the last line of a file on UNIX Box

Dear Friends,

I would like to apend the last line of one file on my UNIX box. Please let me know if you have any suggetsion for this.

E.g: I have a file ABC as below

Required Help
Rajesh Amathi
|
|
Thanks in advance.

Result: I would like the get the output i.e. file ABC should be as below

Required Help
Rajesh Amathi
|
|
Thanks in advance. Have a nice weekend.

Note: Have a nice weekend should be in the same line not in the next line.
# 2  
Old 05-30-2011
Code:
awk 's{print s}{s=$0}END{print s, "Have a nice weekend."}' ABC

# 3  
Old 05-30-2011
Thanks Franklin,

Your code is working fine if I type the same. I need to modify slightl;y for my requirement. I have changed as below. This is working without any errors but required result is not displayed. My code is as follows

I have created s shell script for this and it looks as follows
Code:
#!bin/ksh
C=`/usr/ucb/sum firstfile'
awk 's{print s}{s=$0}END{print s, $C}' firstfile

This script is executing fine but the file is not getting appended. Please help.

Last edited by Franklin52; 05-30-2011 at 10:14 AM.. Reason: Please use code tags
# 4  
Old 05-30-2011
Code:
#!/bin/ksh

C='/usr/ucb/sum firstfile'

awk -v var=$C 's{print s}{s=$0}END{print s, var}' firstfile


BTW: The shebang should be #!/bin/ksh
# 5  
Old 05-30-2011
Code:
file=$( cat "$filename" )
printf "%s\n" "$file Have a nice weekend."

# 6  
Old 05-31-2011
Through sed..
Code:
#!/bin/ksh
c='Have a great day'
sed '$s/$/ '"$c"'/' inputfile

# 7  
Old 05-31-2011
Thanks All,

@Michael,

Your code is perfect. But the file is not getting saved with the newly written content. How can I save that file?

Thanks,
Rajesh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Transferring the file from one UNIX box to another UNIX box

Hi Folks, I am using winscp to graphiclly move the files from one unix box to another unix box , let say one unix box crediantials is (These are dummy crediantials) xxx -->username yyy -->password and another unix box name is RRR -->username TTT -->password NOW i need to... (4 Replies)
Discussion started by: punpun66
4 Replies

2. Shell Programming and Scripting

how to append blank line in multiple files in unix

Dear All- Please suggest a single unix command which can append blank line in multiple files. I need to achieve this using a single unix command and not a script Please do advice Regards, Suresh (2 Replies)
Discussion started by: sureshg_sampat
2 Replies

3. UNIX for Dummies Questions & Answers

Append line and variable at fixed postion in file in unix

Hi I have a input file ::: 1583904589034853904 1690234849023849023 159823890238409 1690238490238490238490 . . . The output file should have the record 16 appended to the record 15 and a variable should be added at a FIXED POSTION at 55. The records are been processed inside a loop... (3 Replies)
Discussion started by: akashhello
3 Replies

4. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

5. Shell Programming and Scripting

Append each line to next previous line in a file

Hi all, Please help me in providing sample code to append the following 4 lines in one row. Input : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 RXOCF-430 HY1711 1 EXTERNAL ALARM DOOR ALARM Output should be : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 ... (8 Replies)
Discussion started by: sudhakaryadav
8 Replies

6. Shell Programming and Scripting

ftp file starting with particular name on Windows box to Unix box using shell script

Hello all ! I'm trying to write a shell script (bash) to ftp a file starting with particular name like "Latest_" that is present on a Windows box to UNIX server. Basically I want to set this script in the cron so that daily the new build that is posted on the Windows box can be downloaded to the... (2 Replies)
Discussion started by: vijayb4u83
2 Replies

7. UNIX for Advanced & Expert Users

Copy file from unix box to another unix box

Hi, I am new for perl scripting, I need a script to copy a log file /test/test_yyyymmdd.dat from one unix box to another unix box location /check/check1/ at daily 2:00AM, please let me know how to do that...... Regards, Ann (8 Replies)
Discussion started by: fabrine
8 Replies

8. Shell Programming and Scripting

how to compare all files in one unix box has been to copied to another unix box

Hi our unix admin has copied all files from one unix box to new unix box. We just need to confirm that all the file systems are copied properly. How to validate. (9 Replies)
Discussion started by: sravanreddym
9 Replies

9. UNIX for Dummies Questions & Answers

Running UNIX commands remotely in Windows box from Unix box – avoid entering password

I am able to run the UNIX commands in a Windows box from a UNIX box through "SSH" functionality. But whenever the SSH connection is established between UNIX and Windows, password for windows box is being asked. Is there a way to avoid asking password whenever the SSH connection is made? Can I... (1 Reply)
Discussion started by: D.kalpana
1 Replies

10. UNIX for Advanced & Expert Users

How to FTP a file generated at UNIX Box to NT Box

Hi all, I am generating a file on the Unix machine , now i want to FTP the same file to the NT machine. how can i do that and the application currently upon which i am working is a JAVA based application. I need your help. regards Ruchir (2 Replies)
Discussion started by: Ruchir
2 Replies
Login or Register to Ask a Question