error in awk of shell script -
i getting below error ith code.what missing in it? goal print 13.0.5.8 in $version
#!/bin/ksh file="abc_def_app_13.0.5.8" if echo "$file" | grep -e "abc_def_app"; echo "version found: $file" version1=(echo $file | awk -f_ '{print $nf}' | cut -d. -f1-3) version2=(echo $file | awk -f_ '{print $nf}' | cut -d. -f4-) echo $version1 echo $version2 version=$version$version2 echo $version else echo "version not found" fi
please find below error:
./version.sh: line 7: syntax error near unexpected token `|' ./version.sh: line 7: ` version1=(echo $file | awk -f_ '{print $nf}' | cut -d. -f1-3)' ./version.sh: line 9: syntax error near unexpected token `|' ./version.sh: line 9: ` version2=(echo $file | awk -f_ '{print $nf}' | cut -d. -f4-)' ./version.sh: line 18: syntax error near unexpected token `else'
it can done in single awk command , without additional cut command. consider following command:
read version1 version2 < <(echo $file|awk -f "[_.]" '{ printf("%s.%s.%s ", $4, $5, $6); printf("%s", $7); (i=8; i<=nf; i++) printf(".%s", $i); print ""}') echo "$version1 :: $version2"
output
13.0.5 :: 8
Comments
Post a Comment