我有一个文件raw-vobs-config-spec,其中有两行
element /vob/ccm_tpl/repository/open_source/ciscossl_fom/4_1/... TPLBASE
element /vob/ccm_tpl/repository/open_source/ciscossl/1_0_2d_5_4/... VERSION_04
我有我的代码:
OLD_VERSION=`grep "ciscossl" raw-vobs-config-spec | cut -d " " -f2 | awk -F "/" '{ print $(NF-1)}'`
echo $OLD_VERSION
total_fields=`grep "ciscossl" raw-vobs-config-spec | cut -d " " -f2 | awk -F "/" '{ print NF }'`
echo $total_fields
#directory_path=`grep "ciscossl" raw-vobs-config-spec | cut -d " " -f2 | cut -d"/" -f1-"${total_fields}"`
#echo $directory_path
loc=`grep "ciscossl" raw-vobs-config-spec_new | cut -d " " -f2 | cut -d"/" -f1-6`
echo $loc
所以它打印o / p为
4_1 1_0_2d_5_4
8 8
/vob/ccm_tpl/repository/open_source/ciscossl_fom
/vob/ccm_tpl/repository/open_source/ciscossl
但我需要输出为
4_1
8
/vob/ccm_tpl/repository/open_source/ciscossl_fom
我怎么能得到它?
答案 0 :(得分:0)
您可以使用read
而不使用while
循环首先只读取一行,然后使用awk
处理读取的文本:
# read one line from input file
read _ line _ < raw-vobs-config-spec
# process the line with awk
echo "$line" | awk 'BEGIN{FS=OFS="/"} {print $(NF-1) ORS NF; NF-=2; print}'
<强>输出:强>
4_1
8
/vob/ccm_tpl/repository/open_source/ciscossl_fom