Solved

SED command

Posted on 2004-09-21
12
349 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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
 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wifi not working on Raspberry Pi 3? 2 56
how to rebuild XFS volume from LV 19 64
Red Hat 7 Linux on Azure cannot run a command as root 22 42
winscp where are logs stored 3 36
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

777 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