Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在文件中每行的开头添加一个递增的数字以及使用 awk 的字符串。
这是我尝试做的事情:
awk 'BEGIN { for ( i=1 ; i <= 60 ; i++ ) print "\""i"\"" "\""$0 }' test1.vdf > test2.vdf
但是这样做只会给我数字并忽略文件中的字符串。
BEGIN 是一种“特殊模式”,仅在第一条记录之前处理
如果您将尝试转移到更有可能的区域,您会发现您不需要“循环”,因为“一次记录一次”的标准过程将为您执行此操作。
尝试这个:
{ print "\""++i"\"" "\""$0 }
我不知道它是否正是您想要的输出,但它主要是您的代码。