Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.