我正在使用awk处理文件,需要跳过一些行.互联网没有一个好的答案.
到目前为止,我唯一的信息是你可以通过以下方式跳过范围:
awk 'NR==6,NR==13 {print}' input.file
Run Code Online (Sandbox Code Playgroud)
要么
awk 'NR <= 5 { next } NR > 13 {exit} { print}' input.file
Run Code Online (Sandbox Code Playgroud)
您可以通过输入跳过第一行:
awk 'NR < 1 { exit } { print}' db_berths.txt
Run Code Online (Sandbox Code Playgroud)
你怎么跳过最后一行?
我试图从平面文件导入一些数据,并得到一些奇怪的结果.导入未附加到日期的时间时,为什么还要在此时插入日期?
1.9.3-p286 :008 > v.arrival_time = Time.parse("10:10")
=> 2012-11-06 10:10:00 -0400
Run Code Online (Sandbox Code Playgroud)
我猜测只有一种方法来保持日期本身,但是尽管有活跃的记录列类型:时间,但没有办法保持时间.有没有办法让它们分开,例如:
1.9.3-p286 :002 > Date.parse("JAN 01 2000")
=> Sat, 01 Jan 2000
Run Code Online (Sandbox Code Playgroud) 我在Mac Terminal Vim中有一系列数字,我按下CTRL- 递增 A.Strangley,当我在的时候07,这个数字会跳过010而不是08.我刚试过MacVim并且发生了同样的行为.有谁知道为什么?
注意:两个Vim都非常适合7.
我一直在使用zsh globbing来执行以下命令:
vim **/filename
vim *.html.erb
Run Code Online (Sandbox Code Playgroud)
等等,但当我输入类似的东西时:
find . -name *mobile*
Run Code Online (Sandbox Code Playgroud)
我收到了回复:
zsh: no matches found: *mobile*
Run Code Online (Sandbox Code Playgroud)
为什么?
说我在我的终端输入的内容如下:
ls | grep phrase
Run Code Online (Sandbox Code Playgroud)
在这之后我意识到我想要删除所有这些文件.
我想使用Ruby来做到这一点,但无法弄清楚要传递给它的内容.
ls | grep phrase | ruby -e "what do I put in here to go through each line by line?"
Run Code Online (Sandbox Code Playgroud) 对于为什么这个RSpec方法不起作用感到困惑.我在这里看到答案:如何使用RSpec的should_raise与任何类型的异常?并尝试了所有提出的组合但由于某种原因,我仍然得到一个NoMethodError.
这是例外
Exception encountered: #<NoMethodError: undefined method `expect' for #<Class:0x007fa5bd8e4120>>
Run Code Online (Sandbox Code Playgroud)
这是方法:
describe "admin should not be accesible" do
expect { User.new(name: "Example Name", email: "email@example.org", password: "foobar", password_confirmation: "foobar", admin: "true") }.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
end
Run Code Online (Sandbox Code Playgroud)
我之前得到了这个错误,所以我知道我的方法正在做我想做的事情:
1) User admin should not be accesible
Failure/Error: hey = User.new(name: "Hello", email: "hey@hey.org", password: "foobar", password_confirmation: "foobar", admin: "true")
ActiveModel::MassAssignmentSecurity::Error:
Can't mass-assign protected attributes: admin
Run Code Online (Sandbox Code Playgroud)
我在跑步:
Rails 3上的RSpec 2.1.0,防护装置0.3.2和spork 0.9.0
我不确定为什么这不起作用,我找不到解决方案.非常简单,我正在运行一个小脚本require 'CSV',它在我的Mac上使用1.9.3-p327工作正常,但在p374上没有在服务器上运行.
我得到的错误是
/home/deployer/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
require': cannot load such file -- CSV (LoadError)<br> from /home/deployer/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/rubygems/custom_require.rb:36:inrequire'
我的一个模型有以下关系:
class User(Base):
account = relationship("Account")
Run Code Online (Sandbox Code Playgroud)
我想手动设置帐户ID.
我的第一次尝试是这样的:
class User(Base):
account = relationship("Account")
accounts_id = Column(Integer, ForeignKey("accounts.id"), nullable=True)
@classmethod
def from_json(cls, json):
appointment = Appointment()
appointment.account_id = json["account_id"]
return appointment
Run Code Online (Sandbox Code Playgroud)
以上都不行.我们不能引用此列,因为SQLAlchemy会引发一个拟合.这是例外:
sqlalchemy.exc.InvalidRequestError: Implicitly combining column users.accounts_id with column users.accounts_id under attribute 'accounts_id'. Please configure one or more attributes for these same-named columns explicitly.
Run Code Online (Sandbox Code Playgroud)
我试图通过文档进行搜索,并且通过多种方式获取属性但是我无法找到,更不用说设置它了.
print(self.account.account_id)
print(self.account.relationhip)
print(self.account.properties)
print(self.account.primaryjoin)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
[编辑 - 上面添加的例外]
我正在开发一个遗留数据库,没有我可以修改的系统.由于类型提供程序,我决定使用F#.我现在并不是那么简单.如何在我的数据库中构建一个只包含以下字符串的字段?它有点像ENUM.我尝试了以下但是还没有完全理解.
尝试1
type SuspendedDriver = "SI"
type ActiveDriver = "IMPRESO"
type Applicant = "NO"
type TemporaryDriver = "TEMP"
type Uncertain = "NULL"
type DriverStatus =
| SuspendedDriver
| ActiveDriver
| Applicant
| TemporaryDriver
| Uncertain
type Driver = {
status : DriverStatus
}
Run Code Online (Sandbox Code Playgroud)
错误
Error FS0618: Invalid literal in type (FS0618) (ScriptTest)
Run Code Online (Sandbox Code Playgroud)
尝试2
type DriverStatus =
| SuspendedDriver = "SI"
| ActiveDriver = "IMPRESO"
| Applicant = "NO"
| TemporaryDriver = "TEMP"
| Uncertain = "NULL"
Run Code Online (Sandbox Code Playgroud)
错误
Error FS0951: Literal …Run Code Online (Sandbox Code Playgroud)