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 > 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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to read record by record from a file in unix raoscb UNIX for Dummies Questions & Answers 1 05-16-2008 06:30 AM
Delete particular value from file using 'sed' sai_nj Shell Programming and Scripting 2 03-31-2008 12:38 AM
Script to search a bad record in a file then put the record in the bad file shilendrajadon UNIX for Advanced & Expert Users 1 12-28-2007 10:00 AM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 01:58 PM
command to remove last record on file mheinen UNIX for Dummies Questions & Answers 4 01-09-2007 04:39 PM

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 06-29-2007
Roopanwita Roopanwita is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 4
Usiung last record of file using 'sed' command

Hi,
In my Scripts,i need to read record from a file and after reading I need to delete that record,as I need to run the script in a loop for no of records in file.( I am using While-do command for that).But my problem is while deleting record using command"`cat ${TEST_FILE}|sed '$d' > ${TEST_FILE}`",first time it is deleting record properly but in second reu(in while loop),it is deleting all records at same time.
Please suggest some solution.
Thanks in advance
  #2 (permalink)  
Old 06-29-2007
Roopanwita Roopanwita is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 4
Delete last record from file using "Sed"

Hi,
In my Scripts,i need to read record from a file and after reading I need to delete that record,as I need to run the script in a loop for no of records in file.( I am using While-do command for that).But my problem is while deleting record using command"`cat ${TEST_FILE}|sed '$d' > ${TEST_FILE}`",first time it is deleting record properly but in second reu(in while loop),it is deleting all records at same time.
Please suggest some solution.
Thanks in advance
  #3 (permalink)  
Old 06-29-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Code:
sed '$d' ${TEST_FILE} > ${TEST_FILE}.new && mv ${TEST_FILE}.new ${TEST_FILE}
Cheers
ZB
  #4 (permalink)  
Old 06-29-2007
Roopanwita Roopanwita is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 4
Reply to query "delete last record using sed"

I think my qrery is doing same this,insted of writing output (after deletion of record from file) to new file and then moving the new file again into same (original file) I am over writing writing in the same file.
  #5 (permalink)  
Old 06-29-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Yes, that's your problem. Unless you're using GNU sed (with the -i option) don't do things this way or you'll clobber your original file.
  #6 (permalink)  
Old 06-29-2007
Roopanwita Roopanwita is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 4
Thanks .
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 05:03 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