天涯尽头无女友
您能否尝试以下操作,仅在 GNU 中使用所示示例进行编写和测试awk。awk 'BEGIN{ FS="-" OFS="."}$1==$2 || NF==1{ print $1 next}{ num1=split($1,arr1,".") num2=split($2,arr2,".") for(i=arr1[num1];i<=arr2[num2];i++){ print arr1[1],arr1[2],arr1[3],i }}' Input_file说明:对上述内容添加详细说明。awk ' ##Starting awk program from here.BEGIN{ ##Starting BEGIN section of this program from here. FS="-" ##Setting field separator as - here. OFS="." ##Setting output field separator as . here.}$1==$2 || NF==1{ ##Checking condition if 1st field is equal to 2nd field OR number of fields is 1 then do following. print $1 ##Printing 1st field of current line here. next ##next will skip all further statements from here.}{ num1=split($1,arr1,".") ##Splitting $1 into arr1 with delimiter . AND num1 will have total number of elements in arr1. num2=split($2,arr2,".") ##Splitting $2 into arr2 with delimiter . AND num2 will have total number of elements in arr1. for(i=arr1[num1];i<=arr2[num2];i++){ ##Running for loop from last value of 1st field to last value of 2nd field. print arr1[1],arr1[2],arr1[3],i ##Printing arr1 1st, 2nd and 3rd value and then printing value of i here. }}' Input_file ##Mentioning Input_file name here.