The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing a line in a file - HELP!!! maxmave Shell Programming and Scripting 1 06-04-2008 08:55 PM
Replacing end of line with " in a UNIX file The Observer Shell Programming and Scripting 2 05-17-2008 02:20 AM
replacing a line of unknown charecters in a file malavm Shell Programming and Scripting 12 07-26-2007 01:25 AM
Replacing characters in file with line break johnemb Shell Programming and Scripting 10 04-26-2007 04:38 AM
replacing first line or lines in a file Terrible UNIX for Advanced & Expert Users 3 06-28-2006 05:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 135
Arrow Replacing the last data of each line ina file

Hi,

I ahve a file where the format is as given below:

qqq dfsf gdfjkg gjdosjg jkflsjd 21
fdksdlf fsdnkfl lkdfsgjld 45
laefsdl fsdlfksl fsdklflk gfsdl 56

I need to replace the last number by space or delete the last number in each line. (by using awk/sed/grep)

Can U please help me with this .

thanks in advance
Js
Reply With Quote
Forum Sponsor
  #2  
Old 01-31-2008
Registered User
 

Join Date: Apr 2007
Location: Kolkata
Posts: 81
Thumbs up

Dear jisha,

u can try this

sed 's/[0-9]*$//' filename

Regards,
Pankaj
Reply With Quote
  #3  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 135
Thank you so much Pankaj
Its working
Js
Reply With Quote
  #4  
Old 07-30-2008
Registered User
 

Join Date: Jul 2008
Posts: 1
hi
i m not geeting any command for writing data in any existing file at end
of file though linux commands.plz suggest me anything for it.

kranti
Reply With Quote
  #5  
Old 07-30-2008
Registered User
 

Join Date: Jul 2008
Location: BlackMesh Managed Hosting
Posts: 66
Quote:
Originally Posted by kranti hande View Post
hi
i m not geeting any command for writing data in any existing file at end
of file though linux commands.plz suggest me anything for it.

kranti
Parser failed; syntax error at line 1.
Reply With Quote
  #6  
Old 08-03-2008
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 476
Code:
awk '{for(i=1;i<=NF-1;i++){printf("%s ",$i)};print "";}' filename
Reply With Quote
  #7  
Old 08-04-2008
ynilesh's Avatar
Registered User
 

Join Date: Oct 2007
Location: Bangalore, India.
Posts: 174
hello kranti,
You can just append command output to the file like,

Code:
command >> filename
- nilesh
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0