首页 > 代码库 > 用sed删除空行
用sed删除空行
用sed删除空行
我的代码如下:
class Song
def initialize(name)
@name = name
end
def tell
puts @name
end
end
class ZhouSong < Song
def initialize(name,artist)
super(name)
@artist = artist
end
def tell
super
puts @artist
end
def name=(newName)
@name = newName
end
attr_writer :artist
end
s = Song.new("song")
s.tell
zs = ZhouSong.new("zhousong","zhoujielun")
zs.tell
zs.name = "name : new zhou song"
zs.tell
zs.artist = "artist : zhoujielun "
zs.tell
我希望删除所有的空行,可以用sed来实现
文件名是a.rb
more a.rb | sed "/^\s*$/d"
结果如下:
class Song
def initialize(name)
@name = name
end
def tell
puts @name
end
end
class ZhouSong < Song
def initialize(name,artist)
super(name)
@artist = artist
end
def tell
super
puts @artist
end
def name=(newName)
@name = newName
end
attr_writer :artist
end
s = Song.new("song")
s.tell
zs = ZhouSong.new("zhousong","zhoujielun")
zs.tell
zs.name = "name : new zhou song"
zs.tell
zs.artist = "artist : zhoujielun "
zs.tell
如果您想直接修改文件,那么可以用
sed -i "/^\s*$/d" a.rb
class Song
def initialize(name)
@name = name
end
def tell
puts @name
end
end
class ZhouSong < Song
def initialize(name,artist)
super(name)
@artist = artist
end
def tell
super
puts @artist
end
def name=(newName)
@name = newName
end
attr_writer :artist
end
s = Song.new("song")
s.tell
zs = ZhouSong.new("zhousong","zhoujielun")
zs.tell
zs.name = "name : new zhou song"
zs.tell
zs.artist = "artist : zhoujielun "
zs.tell
我希望删除所有的空行,可以用sed来实现
文件名是a.rb
more a.rb | sed "/^\s*$/d"
结果如下:
class Song
def initialize(name)
@name = name
end
def tell
puts @name
end
end
class ZhouSong < Song
def initialize(name,artist)
super(name)
@artist = artist
end
def tell
super
puts @artist
end
def name=(newName)
@name = newName
end
attr_writer :artist
end
s = Song.new("song")
s.tell
zs = ZhouSong.new("zhousong","zhoujielun")
zs.tell
zs.name = "name : new zhou song"
zs.tell
zs.artist = "artist : zhoujielun "
zs.tell
如果您想直接修改文件,那么可以用
sed -i "/^\s*$/d" a.rb
用sed删除空行
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。