LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-09-2006, 08:26 PM   #1
3saul
Member
 
Registered: Aug 2004
Location: Brisbane, Australia
Distribution: Ubuntu/Fedora
Posts: 86

Rep: Reputation: 15
A difficult SED question...


If I have the text
1234x321

and I want to remove anything past the x (ie x321)...where I won't know what is after x...can this be done with SED?

For exampe I may get:

1x1 or 00000000x4511511 - I need to remove whatever is after and including x
 
Old 01-09-2006, 08:42 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
You didnīt say which x but I think you meant the second one. Therefore, I put two digits ( .. ) before the x so it would select the second one.

sed 's/\(.*\)x\(.*\)/\1/' file.txt

Last edited by homey; 01-09-2006 at 10:01 PM.
 
Old 03-08-2006, 08:10 PM   #3
3saul
Member
 
Registered: Aug 2004
Location: Brisbane, Australia
Distribution: Ubuntu/Fedora
Posts: 86

Original Poster
Rep: Reputation: 15
Thanks for the reply but I'm wanting to be able to separate a resolution string. For example:

I get this string:
800x600

I need to get both 800 and 600 as separate values. In other words delete anything after the x (x600 to get 800) and in another call delete anything before the x (800x to get 600). But this can also apply to other resolutions that are perhaps smaller or larger:

1024x768
90x800

so the SED command has to look for the 'x'
 
Old 03-08-2006, 08:40 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Does it have to be sed? The following returns 600:
Code:
echo 800x600 | cut -dx -f2
 
Old 03-08-2006, 09:05 PM   #5
3saul
Member
 
Registered: Aug 2004
Location: Brisbane, Australia
Distribution: Ubuntu/Fedora
Posts: 86

Original Poster
Rep: Reputation: 15
That's even better...thanks a lot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Yet another SED Question...but more difficult... 3saul Linux - Software 3 01-06-2006 03:15 AM
Why it is so difficult do insert a new question Paul7 LQ Suggestions & Feedback 10 08-15-2005 09:42 AM
question on sed tifu Linux - Newbie 3 03-18-2005 04:38 PM
A question on 'sed' Barbarian Programming 4 04-11-2002 10:19 PM
sed question 360 Programming 2 03-15-2002 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration