• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 896
  • Last Modified:

SED - get only first nine characters on a line

Hi there,

i'm trying to get the first nine characters only from a line, using SED on mac OS.
Thing is i don't know how to do it, i have only basic SED/reg exp  knowledge.

Any ideas ?

Thanks by advance

Terence
0
terencepires
Asked:
terencepires
2 Solutions
 
Maciej SsysadminCommented:
cut version:
echo "some long line you want to cut" | cut -c1-9

sed version 1:
echo "some long line you want to cut" | sed 's/^\(.........\).*/\1/'

sed version 2:
echo "some long line you want to cut" | sed 's/^\(.\{9\}\).*/\1/'
0
 
isarasooCommented:
why not use cut insted of sed i.e.

echo line | cut -c-9
this cuts the first 9 characters of the line that you echo out and
0
 
terencepiresAuthor Commented:
thanks to you two, and especially oklit for such a complete solution

cheers

Terence
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now