- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: remove blank line from end of ascii file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 02:27 PM
тАО02-20-2002 02:27 PM
remove blank line from end of ascii file
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 02:37 PM
тАО02-20-2002 02:37 PM
Re: remove blank line from end of ascii file
ed yourfile << EOT
\$g/^\$/d
w
q
EOT
( $g/^$/d : search through last line, for empty line & delete). Should work if it's not an extremely large file.
good luck,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 08:26 PM
тАО02-20-2002 08:26 PM
Re: remove blank line from end of ascii file
#!/usr/bin/ksh
if [ `tail -i yourfile | tr -d " " | tr -d "\t" | wc -c` -eq 1 ]
then
lines=`wc -l yourfile | cut -d" " -f1`
head -`expr $lines -1` yourfile > yourfile.out
mv -f yourfile.out yourfile
fi
In case you want spaces and tabs on the last line to be considered as valid non-blank characters, just delete the 'tr -d' commands on the first line.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 08:39 PM
тАО02-20-2002 08:39 PM
Re: remove blank line from end of ascii file
Replace the "tail -i yourfile" in the first line of my script with "tail -1 yourfile"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 09:55 PM
тАО02-20-2002 09:55 PM
Re: remove blank line from end of ascii file
Here is a simple script that can do the job for you :
You can make it more meaningful and efficient by adding more print statements
#!/bin/ksh
grep "^$" testthis | tail -1 > testthis.out
if [[ -s testthis.out ]]; then
print "Blank line exists in the last line of this file"
rm -f testthis.out
else
print "Blank line does not exist in the last line of this file"
fi
-Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2002 10:34 PM
тАО02-20-2002 10:34 PM
Re: remove blank line from end of ascii file
I didn't read your posting properly, thought you wanted the file removed...
Anyway... if there is a blank line in an ascii file and if you would like that blank line removed then do:
#!/bin/ksh
grep "^$" testthis | tail -1 > testthis.out
if [[ -s testthis.out ]]; then
print "Blank line exists in the last line of this file"
print "Removing blank line.. newfile is cleanfile.out
sed '/^$/d' testthis > cleanfile.out
else
print "Blank line does not existin the last line of this file"
fi
-Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2002 12:41 AM
тАО02-21-2002 12:41 AM
Re: remove blank line from end of ascii file
...and using awk...
awk 'NR==1{line=$0;next}
{print line;line=$0}
END{if (line !~ /^[ ]*$/)print line}' yourfile
The square brackets contain -space- followed by -tab-
Rgds, Robin