使用带有特殊字符的xargs

使用带有特殊字符的xargs

本文介绍了使用带有特殊字符的xargs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题.得到了一个文件,其中包括FS的某些路径/文件.出于某些原因,它们确实包括整个特殊字符,例如空格,单引号/双引号,甚至有时包括版权ASCII.

I have the following problem.Got a file which includes certain paths/files of a FS.These for some reason do include the whole range of special characters, like space, single/double quotes, even sometimes the Copyright ASCII.

我需要运行文件的每一行并将其传递给另一个命令.

I need to run each line of the file and pass it to another command.

到目前为止,我尝试过的是:

What I tried so far is:

<input_file xargs -I % command %

在我从xargs收到此消息之前一直在工作

Which was working until I got this message from xargs

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

但是usinf这个选项对我来说根本不起作用

But usinf this option did not work at all for me

xargs: argument line too long

有人能解决带有特殊字符的问题吗?不必与xargs一起使用,但是我需要将行直接传递给命令.

Does anybody have a solution which does work ok with special characters.Doesn't have to be with xargs, but I need to pass the line as it is to the command.

非常感谢.

推荐答案

您应使用\0 NULL字符分隔文件名以进行处理.

You should separate the filenames with the \0 NULL character for processing.

这可以通过

find . <args> -print0 | xargs -0

或者如果您必须使用文件名处理文件,则将"\ n"更改为"\ 0",例如

or if you must process the file with filenames, change the '\n` to '\0', e.g.

tr '\n' '\0' < filename | xargs -0 -n1 -I% echo "==%=="

-n 1说,

,您应该使用"%"引号将%

这篇关于使用带有特殊字符的xargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:15