Solved

SED - get only first nine characters on a line

Posted on 2009-04-08
3
889 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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