Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SED - get only first nine characters on a line

Posted on 2009-04-08
3
Medium Priority
?
894 Views
Last Modified: 2012-05-06
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
Comment
Question by:terencepires
3 Comments
 
LVL 23

Accepted Solution

by:
Maciej S earned 1600 total points
ID: 24097232
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
 
LVL 1

Assisted Solution

by:isarasoo
isarasoo earned 400 total points
ID: 24097253
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
 
LVL 1

Author Comment

by:terencepires
ID: 24097368
thanks to you two, and especially oklit for such a complete solution

cheers

Terence
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question