你能帮忙找一个可以对文件做的命令:
输入-1:
/*
* Copyright (c) 1992-2013 Some comp, Inc and/or its affiliates. All rights reserved.
* Some comp PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
* Author: aaaa
* DateCreated: aaaa
* Last Modified By: aaaa
* Modified Time: aaaa
* File Version: aaaa
* File Path: aaaa
*/
以上所有行都应删除并替换为
/*
* Copyright (c) 1992-2013 some comp, and/or its affiliates. All rights reserved.
* some comp PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
* Author: bbbb
* DateCreated: bbbb
* Last Modified By: bbbb
* Modified Time: bbbb
* File Version: bbbb
* File Path: bbbb
*/
我的意见是,首先从' / '删除到' /'首次出现或删除直到* /从文件开始。 然后,用文件顶部的第二个行替换。
答案 0 :(得分:0)
使用带有sed和awk的正则表达式。 Gawk有一个名为gsub的函数用于替换文本。
答案 1 :(得分:0)
假设文件名为filename
。在newcopyright
中保存没有第一行和最后一行的新文本(即从“* Copyright ...”到“* File Path ...”)。然后:
sed -e '/Path/ r newcopyright' -e '/Copyright/,/Path/d' filename
这会将新文件发送到标准输出(即您的屏幕)。您可以将其重定向到新文件,或者如果要修改文件,可以执行以下操作:
sed -i '.save' -e '/Path/ r newcopyright' -e '/Copyright/,/Path/d' filename