I want to move the output of the command:
我想移动命令的输出:
ls -1 /${TMP_DIR}/*0000000221*.dbf | xargs | sed 's/ /,/g'
In the end of a command that come after it, like that:
在它之后的命令的末尾,像这样:
ls -1 /${TMP_DIR}/*0000000221*.dbf | xargs | sed 's/ /,/g' | impdp sim/sim files=$1
For example:
例如:
execute ls -1 /${TMP_DIR}/*0000000221*.dbf | xargs | sed 's/ /,/g'
will give me:
执行ls -1 /${TMP_DIR}/*0000000221*.dbf | xargs | sed's / /,/ g'会给我:
/tmp/a_0000000221.dbf,/tmp/a_00000002212.dbf,/tmp/b_0000000221.dbf
/tmp/a_0000000221.dbf,/tmp/a_00000002212.dbf,/tmp/b_0000000221.dbf
So I want the final command will look like:
所以我想最后的命令看起来像:
impdp sim/sim files=/tmp/a_0000000221.dbf,/tmp/a_00000002212.dbf,/tmp/b_0000000221.dbf
EDIT: Sorry I didnt write this from the beginning - I've variable in the command ${TMP_DIR}
编辑:对不起,我没有从头开始写这个 - 我在命令$ {TMP_DIR}中有变量
5 个解决方案
#1
0
ls
is a bit redundant if you just want to get the file names. You can get the shell to glob those and then use printf to put them one per line.
如果您只想获取文件名,则ls有点多余。你可以让shell为glob那些,然后使用printf每行放一个。
To separate those items with ',' rather than '\n', you can use paste
要使用','而不是'\ n'分隔这些项目,您可以使用粘贴
Finally, putting all that within $() will execute that in a subshell, and output the result for the command in the current shell.
最后,将所有内容放在$()中将在子shell中执行,并在当前shell中输出命令的结果。
impdp sim/sim files=$(printf '%s\n' /${TMP_DIR}/*0000000221*.dbf | paste -d, -s)
#2
1
You probably don't need that many pipes. You can use it like this:
你可能不需要那么多管道。你可以像这样使用它:
printf "impdp sim/sim files=" && printf "%s," /tmp/*0000000221*.dbf
impdp sim/sim files=/tmp/a_0000000221.dbf,/tmp/a_00000002212.dbf,/tmp/b_0000000221.dbf,
#3
0
You can try other order of commands:
您可以尝试其他命令顺序:
impdp sim/sim files=$(ls -1 /tmp/*0000000221*.dbf | xargs | sed 's/ /,/g')
#4
0
You can use globbing, an array and IFS
to construct the parameter string:
您可以使用globbing,数组和IFS来构造参数字符串:
$ ls -1
1.txt
2.txt
3.txt
$ echo impdp sim/sim files="$(a=(*.txt);IFS=',';echo "${a[*]}")"
impdp sim/sim files=1.txt,2.txt,3.txt
Obviously this will break on filenames with spaces or newlines.
显然,这会破坏带有空格或换行符的文件名。
To run, just remove the echo
.
要运行,只需删除回声即可。
#5
0
(all solutions including mine assumes your filenames do not contain spaces)
sed is a little overkill, you can use tr and avoid xargs too:
(包括我的所有解决方案都假设您的文件名不包含空格)sed有点矫枉过正,您可以使用tr并避免使用xargs:
impdp sim/sim files=$(ls /tmp/*0000000221*.dbf | tr "\n" ",")
#1
0
ls
is a bit redundant if you just want to get the file names. You can get the shell to glob those and then use printf to put them one per line.
如果您只想获取文件名,则ls有点多余。你可以让shell为glob那些,然后使用printf每行放一个。
To separate those items with ',' rather than '\n', you can use paste
要使用','而不是'\ n'分隔这些项目,您可以使用粘贴
Finally, putting all that within $() will execute that in a subshell, and output the result for the command in the current shell.
最后,将所有内容放在$()中将在子shell中执行,并在当前shell中输出命令的结果。
impdp sim/sim files=$(printf '%s\n' /${TMP_DIR}/*0000000221*.dbf | paste -d, -s)
#2
1
You probably don't need that many pipes. You can use it like this:
你可能不需要那么多管道。你可以像这样使用它:
printf "impdp sim/sim files=" && printf "%s," /tmp/*0000000221*.dbf
impdp sim/sim files=/tmp/a_0000000221.dbf,/tmp/a_00000002212.dbf,/tmp/b_0000000221.dbf,
#3
0
You can try other order of commands:
您可以尝试其他命令顺序:
impdp sim/sim files=$(ls -1 /tmp/*0000000221*.dbf | xargs | sed 's/ /,/g')
#4
0
You can use globbing, an array and IFS
to construct the parameter string:
您可以使用globbing,数组和IFS来构造参数字符串:
$ ls -1
1.txt
2.txt
3.txt
$ echo impdp sim/sim files="$(a=(*.txt);IFS=',';echo "${a[*]}")"
impdp sim/sim files=1.txt,2.txt,3.txt
Obviously this will break on filenames with spaces or newlines.
显然,这会破坏带有空格或换行符的文件名。
To run, just remove the echo
.
要运行,只需删除回声即可。
#5
0
(all solutions including mine assumes your filenames do not contain spaces)
sed is a little overkill, you can use tr and avoid xargs too:
(包括我的所有解决方案都假设您的文件名不包含空格)sed有点矫枉过正,您可以使用tr并避免使用xargs:
impdp sim/sim files=$(ls /tmp/*0000000221*.dbf | tr "\n" ",")