Solved

SED command

Posted on 2004-09-21
12
343 Views
Last Modified: 2010-04-20
Hi,

When I run this:

echo 1_2_spell.xml | sed 's/\([^\_]*\)\_\([^\_]*\.xml\)/\1.\2/'

I got the result :

1_2.spell.xml

How do I change the sed command switches to make it come out with:

1.2_spell.xml

instead?

Thanks.
CM
0
Comment
Question by:hocheeming
  • 3
  • 2
  • 2
  • +1
12 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 12119960
echo 1_2_spell.xml | sed 's/\([^\_]*\)\_\([^\_]*\)\_\([^\_\.]*\)\.xml/\1.\2\_\3\.xml/'


seems to work
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 12138921
Not sure what you are trying to do here?

But this works:

echo 1_2_spell.xml | sed 's/_/\1./'

...perhaps a more comprehensive example of the stream and manipulation required would be helpful?...or are we going for an obfusication award?

0
 
LVL 22

Expert Comment

by:pjedmond
ID: 12138945
..or even:

echo 1_2_spell.xml | sed 's/_/./'

as long as you don't stipulat the g (global obtion, only the first _ will be substituted!
0
 

Author Comment

by:hocheeming
ID: 12139180
How can I make a check in the characters between the "_" to be numeric?

For exp:

1_2_spell.xml convert 1.2_spell.xml

but for

1700_command_spell.xml (ignore: dun convert as "command" is non numeric)

Thanks.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Expert Comment

by:avizit
ID: 12139620
check for numeric as  

[0-9]+
0
 

Expert Comment

by:dReichel
ID: 12140767
echo 12.34_Abc.xml
echo 12.34_Abc.xml | sed -e 's/\([0-9]\+\)\.\([0-9]\+\)_\([^0-9]\+\)\.xml/\1_\2.\3.xml/'
0
 

Author Comment

by:hocheeming
ID: 12196443
It gives :

12_34.Abc.xml

I need:

12.34_Abc.xml

Please advise.

Thanks.
CM
0
 

Accepted Solution

by:
dReichel earned 50 total points
ID: 12253381
Oh - sorry :)

echo 12_34.Abc.xml
echo 12_34.Abc.xml | sed -e 's/\([0-9]\+\)_\([0-9]\+\)\.\([^0-9]\+\)\.xml/\1.\2_\3.xml/'

I tested it and it does produce

12.34_Abc.xml

Going back to your original question, the above script will transform 1_2_spell.xml to 1.2_spell.xml  Hopefully it will reject unwanted matches.
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 13088999
I would have thought that my solution and that of avizit also did what was required. The check for numbers was an additional insight.

Anyway - your call:)
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now