Solved

SED - get only first nine characters on a line

Posted on 2009-04-08
3
875 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 400 total points
Comment Utility
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 100 total points
Comment Utility
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
Comment Utility
thanks to you two, and especially oklit for such a complete solution

cheers

Terence
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now