- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Delete blanks lines in a text plain 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
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
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-18-2010 12:16 PM
02-18-2010 12:16 PM
Delete blanks lines in a text plain file
You know, I've been looking for any kind of command with sed or awk for deleting blanks lines in a txt file on a HP-UX server.
I already got the filtered file and I found a web page in which they say with the expression "sed '/^$/d'" but this isn´t working for me.
Can anybody help me with this?
Thanks a lot!
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 12:21 PM
02-18-2010 12:21 PM
Re: Delete blanks lines in a text plain file
sed /^$/d my.file
post your error, maybe that will help ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 12:48 PM
02-18-2010 12:48 PM
Re: Delete blanks lines in a text plain file
# perl -pi.old -e 's/^\s*$//' file
...will eliminate all blank lines from your file after creating a backup copy suffixed with ".old".
This works for lines that consist only of a newline or lines that have leading spaces and/or tab characters only.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 01:19 PM
02-18-2010 01:19 PM
Re: Delete blanks lines in a text plain file
# sed '/^$/d' testfile # Delete blank Line from a file using sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 01:32 PM
02-18-2010 01:32 PM
Re: Delete blanks lines in a text plain file
To be clear:
# sed /^$/d file
...will *not* delete "blank" lines unless those lines consist *only* of a newline character --- without leading whitespace.
The Perl snippet I suggested works both for lines that consist only of a newline or lines that have leading spaces and/or tab characters only before the final newline character.
If you insist on 'sed', this mimics the Perl snippet albeit without the inplace file modication:
# sed -e '/^[ ]*$/d' file
Notice carefully that the characters between the square brackets are really a blank and a tab. HP-UX's 'sed' doesn't allow metacharacters like '\t' to a tab. HP-UX's 'sed' doesn't allow inplace modification, either.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 01:38 PM
02-18-2010 01:38 PM
Re: Delete blanks lines in a text plain file
sed '/^[[:space:]]*$/d'
And it has the benefit of being easier to read than the brackets with a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 06:27 PM
02-18-2010 06:27 PM
Re: Delete blanks lines in a text plain file
awk NF data.txt
This handles zero length lines, spaces and tabs -- any number on the blank lines.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 07:24 PM
02-18-2010 07:24 PM
Re: Delete blanks lines in a text plain file
>> any kind of command with sed or awk
You got great answers for sed/awk. In case you look for anything else, try this:
# more filename | grep -v ^$
Regds..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 07:34 PM
02-18-2010 07:34 PM
Re: Delete blanks lines in a text plain file
Not sure why you want more(1) involved?
(Unless you want to use -s to give grep a head start? :-)
Just use: grep -v ^$ filename
Or: grep -v '^[[:space:]]*$' filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 07:37 PM
02-18-2010 07:37 PM
Re: Delete blanks lines in a text plain file
This will have the same problem as the initial 'sed' statement posted. It will only match lines that consist of a "newline" character ONLY. If there are spaces and/or tabs on the line that will not work.
To take care of spaces and/or tabs you would have to do:
# more filename | grep -v ^[[:space:]]*$
or, even easier with spawning a unnecessary "more" process:
# grep -v ^[[:space:]]*$ filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2010 08:28 PM
02-18-2010 08:28 PM