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 > Special Forums > UNIX Desktop for Dummies Questions & Answers
.
google unix.com



UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Append text at end of the first line in a file catgovind Shell Programming and Scripting 7 05-01-2008 07:33 AM
Append to end of each line of file without a temp file. rorey_breaker Shell Programming and Scripting 4 04-03-2008 10:11 AM
How to Append a Value to each line of the file dsshishya UNIX for Dummies Questions & Answers 11 03-21-2008 02:48 PM
Append a field to the end of each line of a file based on searching another file. ultimate Shell Programming and Scripting 2 03-29-2005 10:21 AM
Large file need to append to each line r1500 UNIX for Dummies Questions & Answers 1 10-14-2003 10:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2007
subhrap.das subhrap.das is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 1
append a line to the last line in a file

Suppose i have a file "xyz.txt" which contains

abcdef
ghijklm
nop



Now in want to add "qrst" to the last line such that the file becomes

abcdef
ghijklm
nopqrst


P.S:The o/p i need is
abcdef
ghijklm
nopqrst (and not) nop
qrst
  #2 (permalink)  
Old 03-28-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
Try this..

Code:
echo "$(cat file)qrst" >temp
mv temp file
O/p:
cat file
abcdef
ghijklm
nop
echo "$(cat file)qrst"
abcdef
ghijklm
nopqrst

Last edited by dennis.jacob; 03-28-2007 at 02:27 AM..
  #3 (permalink)  
Old 03-28-2007
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Using sed

Code:
$ cat xyz.txt
abcdef
ghijklm
nop
$ sed '$ a\qrst' xyz.txt
abcdef
ghijklm
nop
qrst
$ sed '$ a\qrst' xyz.txt > abc.txt
$ mv abc.txt xyz.txt
$ cat xyz.txt
abcdef
ghijklm
nop
qrst
$
  #4 (permalink)  
Old 03-28-2007
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
I seem to have misunderstood the requirement. Hope below is the required soln.

Code:
$ sed '$ s/^\(.*\)$/\1qrst/' xyz.txt
abcdef
ghijklm
nopqrst
  #5 (permalink)  
Old 03-29-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,945
Code:
awk '{ printf "\n%s", $0 }END{ printf "abcdefghijkl\n" }' filename
  #6 (permalink)  
Old 04-25-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
sed '$s/$/&qrst/' input_file
Closed Thread

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 01:21 AM.


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