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
Padding Carriage return to the end of XML file dasj22 UNIX for Advanced & Expert Users 3 05-23-2008 09:31 AM
Issue with Removing Carriage Return (^M) in delimited file sirahc UNIX for Advanced & Expert Users 7 03-25-2008 05:08 AM
add carriage return at end of file HAA Shell Programming and Scripting 2 11-20-2007 11:58 AM
Removing Carriage Return and or line feed from a file tbone231 Shell Programming and Scripting 1 02-18-2005 04:37 PM
Removing carriage return characters from file b1saini UNIX for Dummies Questions & Answers 3 09-10-2003 09:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-20-2006
bd_joy bd_joy is offline
Registered User
  
 

Join Date: Aug 2005
Location: Pittsburgh, PA
Posts: 25
Carriage Return at end of file

Hi, I have a script that outputs a file that contains the dates from the previous month, which is then used by our application to run processes on each date contained in the file. My problem is is that my script created a blank line at the bottom of the file which causes issues for our application. I'm looking for suggestions on how to stop or remove the last line/carriage return. Any suggestions are appreciated. Thanks!


Here is the current script:

echo "Creating DATES file. `date +"%m-%d-%Y_%H:%M:%S"`"
outdir=/test/iofiles

# ja fe ma ap ma ju ju ag se oc no de
set -A lasts 0 31 28 31 30 31 30 31 31 30 31 30 31
typeset -Z2 dmonth dday

month=`date +%m`
year=`date +%y`
((pmonth=month-1))

rm $outdir/date.txt

day=1
while((day<(lasts[pmonth])+1)) ; do
dday=$day
dmonth=$pmonth
echo ${dmonth}/${dday}/${year} >> $outdir/date.txt
((day=day+1))
done
echo "DATES file created. `date +"%m-%d-%Y_%H:%M:%S"`"
  #2 (permalink)  
Old 10-20-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sed "/^ *$/d" $outdir/date.txt > temp
mv temp $outdir/date.txt
  #3 (permalink)  
Old 10-20-2006
bd_joy bd_joy is offline
Registered User
  
 

Join Date: Aug 2005
Location: Pittsburgh, PA
Posts: 25
Quote:
Originally Posted by anbu23
Code:
sed "/^ *$/d" $outdir/date.txt > temp
mv temp $outdir/date.txt
Should I place this after the while loop or within it? I placed it after the loop and I still had the blank line at the end of the file.
  #4 (permalink)  
Old 10-20-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
You have that code at the end of the loop.
Do you mean you have blank line or line with "/" at the end of the file?
  #5 (permalink)  
Old 10-20-2006
bd_joy bd_joy is offline
Registered User
  
 

Join Date: Aug 2005
Location: Pittsburgh, PA
Posts: 25
It just has a blank line at the end

---------------
09/01/06
09/02/06
09/03/06
09/04/06
09/05/06
09/06/06
09/07/06
09/08/06
09/09/06
09/10/06
09/11/06
09/12/06
09/13/06
09/14/06
09/15/06
09/16/06
09/17/06
09/18/06
09/19/06
09/20/06
09/21/06
09/22/06
09/23/06
09/24/06
09/25/06
09/26/06
09/27/06
09/28/06
09/29/06
09/30/06
<---Want to remove this blank line.
--------------------------------

Thanks.
  #6 (permalink)  
Old 10-20-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
sed '$d' myFile.txt
  #7 (permalink)  
Old 10-20-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Above code should work. I dont know whats happening in your case.
Try this

Code:
sed "$ d" $outdir/date.txt > temp
mv temp $outdir/date.txt
Sponsored Links
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 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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