[英]Bash read file line by line, split by tab, send to java application
I want to read from a file line by line, then construct a args string and then use this string to start an java application. 我想逐行读取文件,然后构造一个args字符串,然后使用该字符串启动Java应用程序。
The file test.txt contains for example this lines, columns are tab separated: 例如,文件test.txt包含以下行,各列用制表符分隔:
abc def ghj kln
abc def ghj kln
asd ss fdf twe
asd ss fdf twe
#!/bin/bash
IFS=$'\n'
while read k d a m s
do
echo java -jar test.jar -k $k -d $d -a $a -m $m -s $s
done < test.txt
unfortunatly it does not work. 不幸的是,它不起作用。 bash output is broken:
bash输出损坏:
-k abc def ghj kln -d -a -m -s
-k abc def ghj kln -d -a -m -s
You say the columns are tab separated, so you should use \\t
for IFS
instead of \\n
which means newline: 您说各列之间用制表符分隔,因此对于
IFS
应该使用\\t
而不是\\n
,这意味着换行符:
IFS=$'\t'
(Assuming that each line of the input contains the values for k
, d
, a
, m
, s
separated by tabs). (假设输入的每一行都包含用制表符分隔的
k
, d
, a
, m
, s
的值)。
You just have to change your IFS to separate on tabs \\t
rather then new line \\n
: 您只需要更改IFS以在选项卡
\\t
上分开,而不是在新行\\n
上分开即可:
#!/bin/bash
while IFS=$'\t' read k d a m s
do
echo java -jar test.jar -k "$k" -d "$d" -a "$a" -m "$m" -s "$s"
done < test.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.