小编Pak*_*Pak的帖子

时间戳属性为零

我有2个型号,Microspost并且User:

class Micropost < ActiveRecord::Base
  belongs_to :user
  default_scope -> { order(created_at: :desc) }
  validates :user_id, presence: true
  validates :content, presence: true, length: { maximum: 140 }
end

class User < ActiveRecord::Base
  has_many :microposts, dependent: :destroy
  attr_accessor :remember_token, :activation_token, :reset_token
  before_save   :downcase_email
  before_create :create_activation_digest
  validates :name, presence: true, length: { maximum: 50 }
end
Run Code Online (Sandbox Code Playgroud)

seed.rb :

User.create!(name:  "Example User",
             email: "example@railstutorial.org",
             password:              "foobar",
             password_confirmation: "foobar",
             admin: true,
             activated:    true,
             activated_at: Time.zone.now)
99.times do |n|
  name  = Faker::Name.name …
Run Code Online (Sandbox Code Playgroud)

ruby postgresql ruby-on-rails ruby-on-rails-4

5
推荐指数
1
解决办法
1064
查看次数

如何在 awk 中用零填充 CSV 第一列?

我有一个这样的 CSV:

1,"Paris","3.57"
10,"Singapore","3.57"
211,"Sydney","3.28"
324,"Toronto Center","3.33"
Run Code Online (Sandbox Code Playgroud)

我想用零填充第一列以获得:

001,"Paris","3.57"
010,"Singapore","3.57"
211,"Sydney","3.28"
324,"Toronto Center","3.33"
Run Code Online (Sandbox Code Playgroud)

printf我尝试将第一列分配给awk的输出:

awk '{ $1 = printf("%03d", $1); print }' my.csv
Run Code Online (Sandbox Code Playgroud)

但它给了我一个语法错误:

awk: cmd. line:1: { $1 = printf("%03d", $1); print }
awk: cmd. line:1:        ^ syntax error
Run Code Online (Sandbox Code Playgroud)

如果我引用 printf 函数,它也不起作用。

我怎么能这么做呢?

csv bash awk gawk

1
推荐指数
2
解决办法
1164
查看次数

标签 统计

awk ×1

bash ×1

csv ×1

gawk ×1

postgresql ×1

ruby ×1

ruby-on-rails ×1

ruby-on-rails-4 ×1