Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 967
user1246172 Avatar asked May 23 '12 10:05

user1246172


1 Answers

This might work for you (GNU sed):

echo '1234567890' | sed 's/.//6g'
12345

Or:

echo '1234567890' | cut -c-5
12345
like image 174
potong Avatar answered Sep 21 '22 17:09

potong