sed delete remaining characters in line except first 5
问题 what would be sed command to delete all characters in line except first 5 leading ones, using sed? I've tried going 'backwards' on this (reverted deleting) but it's not most elegant solution. 回答1: This might work for you (GNU sed): echo '1234567890' | sed 's/.//6g' 12345 Or: echo '1234567890' | cut -c-5 12345 回答2: Try this (takes 5 repetitions of 'any' character at the beginning of the line and save this in the first group, then take any number of repetition of any characters, and replace the