- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Delete rogue carriage return (blank space)
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
тАО09-13-2007 10:13 PM
тАО09-13-2007 10:13 PM
test.txt
here
there
everywhere
I use the following sed command to delete the blank lines
sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' test.txt
but i am left with
here
there
everywhere
Can anyone advise how to get rid of the final blank line or last carriage return (i've tried loads of methods to no avail)
Thanks in advance
Declan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 11:15 PM
тАО09-13-2007 11:15 PM
Re: Delete rogue carriage return (blank space)
$ grep -v '^$' test.txt
here
there
everywhere
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 11:23 PM
тАО09-13-2007 11:23 PM
Re: Delete rogue carriage return (blank space)
grep -v '^$' test.txt > test2.txt
still leaves me with
here
there
everywhere
:o(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 11:35 PM
тАО09-13-2007 11:35 PM
Re: Delete rogue carriage return (blank space)
# perl -ni.old -e 'print unless /^\s*$/' file
This will update "file" in-place keeping a backup copy as "file.old".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 11:50 PM
тАО09-13-2007 11:50 PM
Re: Delete rogue carriage return (blank space)
here
there
everywhere
$ grep -v '^$' test.txt > test2.txt
$ cat test2.txt
here
there
everywhere
$ xd -x test2.txt
0000000 6865 7265 0a74 6865 7265 0a65 7665 7279
0000010 7768 6572 650a
0000016
There is no extra newline.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 12:19 AM
тАО09-14-2007 12:19 AM
Re: Delete rogue carriage return (blank space)
Looks like the
That would explain all.
James addresses that with the \s* in the reg expr.
Spex addresses that with the dump, to 'see' the tab(s) (x08) or space(s) (x20) if there are any.
I would use #xd -b test.txt for that.
You can also try to make the blanks visible with something silly like:
awk '{print $0 "*"}' x.awk test.txt
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 03:54 AM
тАО09-14-2007 03:54 AM
Solution... and if you wnt to use 'awk' for skipping empty lines:
awk NF test.txt
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 04:12 AM
тАО09-14-2007 04:12 AM
Re: Delete rogue carriage return (blank space)
Wow, your 'awk' solution deserves a 10+ !!!
I *really* like that. Elegant, to say the very least. Thanks!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 04:42 AM
тАО09-14-2007 04:42 AM
Re: Delete rogue carriage return (blank space)
# cat -vet file
Based on the above output change the sed cmd so that it matches the regexp to a tee or you can try the one below to see if it works:
# sed -n '/^ *$/!p' file
>Peter: awesome awk construct very compact and elegant.
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 12:09 PM
тАО09-14-2007 12:09 PM
Re: Delete rogue carriage return (blank space)
man rmnl
man ssp
but as with previous solutions, an empty line (rmnl and ssp work well) is not the same as a line of blanks or white space. Hats off to the awk solution.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 04:17 PM
тАО09-14-2007 04:17 PM
Re: Delete rogue carriage return (blank space)
>JRF: your 'awk' solution deserves a 10+
>Bill: Hats off to the awk solution.
The only problem will be that you need to have a comment that tells maintainers what it really does. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2007 07:25 PM
тАО09-16-2007 07:25 PM
Re: Delete rogue carriage return (blank space)
seeing the request, I will comment
awk NF test.txt
1) a single awk commandline consists of
statement {action}
which are both optional. If 'statement' evaluates to TRUE 'action' is performed.
Missing statement means: TRUE
Missing action means: print the line
2) the internal awk variable NF contains always the number of fields of the current line (no matter if we are in a statement or an action)
3) we have now no action in the above awk-commandline => print line
4) lines containing only whitespace do not contain any fields, so NF is zero => the statement evaluates to FALSE
1)-4) ==> the awk commandline
NF
selects all non-empty lines only.
mfG Peter
PS: JRF, I was really proud when I saw your comment!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-16-2007 08:09 PM
тАО09-16-2007 08:09 PM
Re: Delete rogue carriage return (blank space)
I figured it out. :-)
>1) a single awk commandline consists of
statement {action}
Actually awk(1) says: pattern {action}
http://docs.hp.com/en/B2355-60130/awk.1.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2007 01:29 PM
тАО09-17-2007 01:29 PM
Re: Delete rogue carriage return (blank space)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2007 02:42 PM
тАО09-17-2007 02:42 PM
Re: Delete rogue carriage return (blank space)
This fails to delete lines with actual spaces.
Using character classes, we can use the following:
$ sed -e '/^[[:space:]]*$/d' test.txt
$ grep -v '^[[:space:]]*$' test.txt