Solved

SED - get only first nine characters on a line

Posted on 2009-04-08
3
885 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
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 100 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

786 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