LinuxQuestions.org
Review your favorite Linux distribution.
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-28-2011, 05:26 PM   #1
tnrooster
Member
 
Registered: Apr 2007
Location: bell buckle tn
Distribution: F13-F14
Posts: 88

Rep: Reputation: 15
sed between command syntax


I'm having trouble getting a sed command to work.

I need to filter a printed line to get characters between 2 expressions. "<job>" and "<url>".

Code:
echo "<job>TEST<url>http://www.project.com/?code=001" | sed 's/^[<job>]*//' | sed 's/[<url>]*$//'
Produces:
Code:
TEST<url>http://www.project.com/?code=001
It takes off the first part but why is that not deleting the "<url>" and all the parts after that?

Thanks, Joe.
 
Old 01-28-2011, 05:36 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,194

Rep: Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040
Most likely because the second expression does not match.
Code:
 sed 's/[<url>]*$//'
tries to match for zero or more ']', but no other characters.

Try this:
Code:
 sed 's/[<url>].*$//'
and it'll work. (note the '.')

jlinkels
 
Old 01-28-2011, 05:50 PM   #3
tnrooster
Member
 
Registered: Apr 2007
Location: bell buckle tn
Distribution: F13-F14
Posts: 88

Original Poster
Rep: Reputation: 15
BAAAA!!

Thank you so much!
 
Old 01-28-2011, 06:22 PM   #4
tnrooster
Member
 
Registered: Apr 2007
Location: bell buckle tn
Distribution: F13-F14
Posts: 88

Original Poster
Rep: Reputation: 15
Well that does work but I seem to be missing something here.

If I extend the data line and include say another field "<img>" and use that as the substitution lookup , it still only returns the same as if I were using "<url>".

Also if I shift the sections over in the data line, ie.. use <url> in the start and <img> in the other , I don't get the parts in between.

Code:
echo "<job>TEST<url>http://www.project.com/?code=001<img>001.png" | sed 's/[<job>]*//;s/[<img>].*$//'
I still get
Code:
TEST
.
 
Old 01-28-2011, 06:49 PM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,194

Rep: Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040
Code:
echo "<job>TEST<url>http://www.project.com/?code=001<img>001.png" | sed 's/<job>//' | sed 's/<img>.*//'
jlinkels
 
Old 01-28-2011, 07:19 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
use awk, forget about sed.

Code:
$ echo "<job>TEST<url>http://www.project.com/?code=001<img>001.png<job>TEST1<url>asdfs" | awk -vRS="<url>" -vFS="<job>" '{print $2}'
TEST
TEST1
 
Old 01-31-2011, 03:55 PM   #7
tnrooster
Member
 
Registered: Apr 2007
Location: bell buckle tn
Distribution: F13-F14
Posts: 88

Original Poster
Rep: Reputation: 15
Thanks everyone, jlinkels. All the parsing is fine for the feed file but I got one issue i can not figure out.

The naming system works for output files on my fedora system but when i moved it to the centos server I'm getting these oddly named files.

For the same feeder file, which is used to name the output files, I get the same odd names each time.

IE.. for files that should be sequential, I'm getting names of
Code:
00TMXU~N.PNG,0YO9CO~D.PNG
and so on.

Always the same ones for instead of the proper filename.

If I remove the file extension I still get the same values.

If I echo the variable used to make the names I get the proper results.

How are these odd names being generated?

Ok its seems the system on which these are being made reads the samba directory correctly. The names all appear to be exactly as the should. When viewing the same files on any other system across the same samba connection they all have the same temp file like names.

Last edited by tnrooster; 01-31-2011 at 04:10 PM. Reason: New Info
 
Old 01-31-2011, 04:32 PM   #8
tnrooster
Member
 
Registered: Apr 2007
Location: bell buckle tn
Distribution: F13-F14
Posts: 88

Original Poster
Rep: Reputation: 15
Its now looking as if there is a special character on the end of the line that maybe handled by fedora and not centos.

Windows line feed most likely, anyone have a way to clear those out via sed?
 
Old 01-31-2011, 05:03 PM   #9
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,194

Rep: Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040Reputation: 1040
Do you mean at the end of each line in the file? Use dos2linux to convert the Window CRLF to Linux LF


jlinkels
 
Old 01-31-2011, 09:08 PM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,953

Rep: Reputation: 691Reputation: 691Reputation: 691Reputation: 691Reputation: 691Reputation: 691
Hi,

I assume that you mean the filenames that are stored inside your document that get messed up by the CR.
Try this
sed -r 's/<job>(.*)<url>.*/\1/'

or
sed -r 's/<job>(.*)<img>.*/\1/'
 
  


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
sed syntax for binary wrapped eps files gs,epstopdf, illustrator tnrooster Linux - Software 1 10-09-2010 03:34 PM
[SOLVED] Question about sed syntax in bash script musonio Linux - Software 2 08-21-2009 08:17 AM
Another SED Syntax Question... stlouis Programming 3 01-17-2008 09:50 PM
SED in BASH Script - Syntax Problem stlouis Programming 4 01-13-2008 11:38 AM
cp command syntax plisken Linux - General 3 11-09-2005 03:51 PM

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

All times are GMT -5. The time now is 01:37 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