I'm not sure what you're trying to do with \s. Is that Perl syntax? It's not in POSIX regular expressions.
Remember that the 's/this/that/' syntax replaces the text it matches. It doesn't put any bit of 'this' back into 'that'. If you have GNU sed, and enable backreferences with the -r flag, you can put brackets around parts you want to match and substitute them in the output string with \1, \2, etc.
That won't help you translate 'a' to '1', though. (I'm not sure from where you're pulling these numbers, either.) The replacements you want are complex: Split a line into elements, for each element match something, read it in, translate it to a number, insert in front... A language like awk would probably be more appropriate than a regex tool like sed.
---------- Post updated at 10:17 AM ---------- Previous update was at 10:06 AM ----------
Think I see better what you're trying to do. sed can do part of it.
[ ]+: match one or more spaces
\& : replace with space, ampersand, space
g: match multiple times per line if possible
You need the -r flag to match "one or more" with + like that. It could be GNU sed only.
+ is not part of basic regular expressions. You would have to do something like this:
or this:
The square brackets are not required. You can use [ \t] instead of each single space in the first part of the sed examples, if you want to replace both spaces and tabs.
Last edited by Scrutinizer; 09-23-2010 at 02:15 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
Unix (and Linux) uses a process tree that gives a natural security, by simple inheritance of attributes.
The following ptree script shows it. It runs on all Linux flavors.
Mostly useful for debugging.
#!/bin/sh
# Solaris style ptree
&& exec /usr/bin/ptree "$@"
... (6 Replies)
Often it has been said that echo is neither portable nor correct.
Here is an input.txt:
line1
line2
-n
line4
-en
line6
-x
line8
Then the following fails with BSD/Linux/bash:
while IFS= read line
do
echo "$line"
done < input.txt
It is elegantly improved by means of an echo... (2 Replies)
Prerequisite:
• S7-2L Server Hardware Console Access
• Solaris 11.3 OS and LDOM Packages (Ex: 3.4)
• Setup IPS Repositories
Solaris 11 comes with Oracle VM server pre-installed if older version is there remove the old and install latest Oracle VM... (1 Reply)
Good Day,
Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp.
sed -n '/regexp/{n;p;}' filename
What if my regexp is 3 word or a sentence. Im... (3 Replies)
I am about to do a script that change the COST so i dont need to change each cost.
The output looks like this.
"OL_ID OL_LINK_COST
----------- ------------
51 10
52 10
53 10
54 10
55 ... (3 Replies)
I need to use tip from machine A serial port to machine B serial port. Can someone point me to an example of the correct cable to use?
Thanks. (1 Reply)