如何根据壳中的恒定变量来解析动态变量?

发布于 2025-01-21 13:29:06 字数 390 浏览 2 评论 0原文

我正在尝试根据我在文本文件中找到的信息来解析两个不同的文本文件,并填充2个配置文件。

这是我使用的:

grep -w -o 50000 granmap.txt

响应:50000,这很好,但是我想要遵循该值的一些信息。

文本文件中信息的格式如下:

50001 |仪器| ATMS

其中50001是常数,“仪器”使文件可读取,而“ atms”是文件之间的更改(这是我想要的信息)。从本质上讲,我想搜索文件以找到50001,以查找与之相等的内容。在这种情况下,50001 = ATM。

如何搜索50001,跳过仪器并抓住ATM位置的价值?也许有一种比使用GREP更强大的方法?

I'm trying to parse two different text files and populate 2 configuration files based on the information I find within the text files.

Here's what I am using:

grep -w -o 50000 GranMap.txt.

Response: 50000, which is good, but I want some of the information that follows that value.

The format of the information within the text files is as follows:

50001|Instrument|ATMS,

where 50001 is the constant, "Instrument" makes the file human readable, and "ATMS" is what changes between files (and is the information I want). In essence, I want to search the file for 50001 to find what is it equal to. In this case 50001 = ATMS.

How can I search for 50001, skip over Instrument, and grab the value that is in the location of ATMS? Maybe there is a more powerful way to do this than using grep?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷荒 2025-01-28 13:29:06

态“文本

awk -F '|' '$1 == 50001 {print $3}' GranMap.txt

ID值可以像这样传递到awk中:

constant=50001
awk -F '|' -v id="$constant" '$1 == id {print $3}' GranMap.txt

is quite good for this kind of "field oriented" text

awk -F '|' '$1 == 50001 {print $3}' GranMap.txt

The id value can be passed into awk like this:

constant=50001
awk -F '|' -v id="$constant" '$1 == id {print $3}' GranMap.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文