Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how to perform by sed in order to print the line until ";" character

    echo "NUMBER   =   3247  FULL DUPLEX ; speed=343 434 " | sed .....

need the following output

NUMBER = 3247 FULL DUPLEX

share|improve this question
up vote 1 down vote accepted

Why don't you use awk for this? i.e.

echo "Number=3247 ; speed=343 434 " | awk {'print $1'}

And if you really need the " in front, use

echo "Number=3247 ; speed=343 434 " | awk {'print "\"" $1'}

EDIT: After feedback (see comments below), here the correct version with sed:

echo "NUMBER = 3247 FULL DUPLEX ; speed=343 434 " | sed 's/\;.*//g'

share|improve this answer
    
not good because Number = 3247 (i have apaces) – jennifer Nov 3 '10 at 13:47
    
see please my update in the question – jennifer Nov 3 '10 at 13:49
    
OK you're right. How about sed 's\; .*//g' then? – socken23 Nov 3 '10 at 13:54
    
echo "NUMBER = 3247 FULL DUPLEX ; speed=343 434 " | sed 's/\; .*//g' (need to add "/" after "s" – jennifer Nov 3 '10 at 14:04
    
you can fix your answer according to your right remark so I will vote for you – jennifer Nov 3 '10 at 14:05

Use awk with -F to specify the field delimiter:

echo "NUMBER   =   3247  FULL DUPLEX ; speed=343 434 " | awk -F\; '{print $1;}'

Note that the semicolon is excaped with a backslash so that your shell won't misinterpret the semicolon as the end of the command.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .