从文件中搜索特定行并将其粘贴到所有其他文件中 [英] Search for a particular line from a file and paste it in all the other files

查看:63
本文介绍了从文件中搜索特定行并将其粘贴到所有其他文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个文件Log.100 Log.200,Log.300 ....它们在一个数组中

Log.100文件包含数据

gpg RC(54321)

测试选项OK

本地= IN

AIX.SHA1.So


和Log.200文件和其他文件包含数据

gpg RC(54321)

测试选项OK

Linux.SHA1.so

除Log.100外,所有文件都错过Local = IN行。所以我想复制一行Local = IN然后将它粘贴到测试选项确定行之后的所有剩余文件中。


注意: - 当我读取文件时通过数组,我不确定哪个文件即(Log.100,Log.200或Log.300我将首先阅读)

所有日志文件都在一个目录中。


我的计划是在perl脚本中使用grep命令并通过数组遍历每个文件,每当它找到行副本并将其保存在变量中并再次遍历所有文件并粘贴所有文件中测试选项确定行之后的变量值。

请提供代码。

你的帮助将不胜感激

谢谢

I have several files Log.100 Log.200,Log.300.... which are in an array
Log.100 file contains the data
gpg RC (54321)
Testion option OK
Local=IN
AIX.SHA1.So

and Log.200 file and other files contains data
gpg RC (54321)
Testion option OK
Linux.SHA1.so
All files misses the line ''Local=IN'' except Log.100. So I want to copy the line Local=IN and then paste it in all the remaining files after the line ''Testing option OK''.

Note:- When I read the files by an array, I am not sure which file i.e (Log.100, Log.200,or Log.300 I will be reading first)
All the Log files are in a one single directory.

My plan was to use grep command in the perl script and traverse each file through an array and whenever it finds that line copy and save it in a variable and again traverse all the files and paste the variable value after the line ''Testion Option OK'' in all the files.
Kindly provide the code.
your help will be appreciated
Thanks

推荐答案

这个问题的哪个部分你有困难?

请具体说明。

您知道如何获取文件名列表吗?

您知道如何打开文件吗? br />
您知道如何测试特定字符串的文件行吗?


显示您的代码,您将获得有关如何改进它的帮助。
With what part of this problem are you having difficulty?
Please be specific.
Do you know how to get a list of file names?
Do you know how to open a file?
Do you know how to test a line of a file for a specific string?

Show your code, and you will get help on how to improve it.


我有这个代码,但我正在寻找简单而复杂的代码。好吧,我希望代码非常容易理解和简单。

I have this code with me, but I am looking at easy and sophisticated code. Well I want the code to be very understandable and easy.

展开 | 选择 < span class =codeDivider> | Wrap | 行号


如果可能,请以简单的方式修改代码。
Kindly modify the code in a simple way, if possible.


这篇关于从文件中搜索特定行并将其粘贴到所有其他文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆