Hi I'm new to this. I need to cut off the last 10 digits from a line.
I've used awk {'print $4'} filename.txt | cut -c 32-42 but this does not guarantee only the last 10 characters.
Please help. Thanks.
Sara
Hi I'm new to this. I need to cut off the last 10 digits from a line.
I've used awk {'print $4'} filename.txt | cut -c 32-42 but this does not guarantee only the last 10 characters.
Please help. Thanks.
Sara
If you are using BASH as shell. This would work.
while read line; do echo ${line:(-10)}; done < filename
Another way using awk(gawk)
awk '{LEN=length($0);print substr($0,LEN-9)}' filename
Other way:
hl=${#line}
ll=$(( hl - 10 ))
echo ${line}|cut -c-${ll}-${hl}
One otherway:
echo $line | awk '{print substr($0, length($0)-9)}'
Thanks guys. They all work. You guys are really good.