Sponsored Content
Full Discussion: Regexp tip
Top Forums Shell Programming and Scripting Regexp tip Post 302456193 by Corona688 on Thursday 23rd of September 2010 12:17:36 PM
Old 09-23-2010
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.

Code:
$ echo a s d f | sed -r 's/[ ]+/ \& /g'
a & s & d & f
$

  • [ ]+: 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.
This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

one teaching Tip

Student have huge interest about why so many expert choose use UNIX than MS Windows. I consider that SHARE & OPEN is key point.:) (2 Replies)
Discussion started by: 111000
2 Replies

2. Solaris

tip into 280R

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)
Discussion started by: dangral
1 Replies

3. Shell Programming and Scripting

Little bit of a help or just a tip

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)
Discussion started by: maskot
3 Replies

4. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

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)
Discussion started by: ownins
3 Replies

5. Solaris

Solaris; tip

plz explain TIP in solaris in detail. (11 Replies)
Discussion started by: karman0931
11 Replies

6. Shell Programming and Scripting

Search tip.

How do I find a key word in multiple files.. in a directory.. ? cat *.doc | grep -i myword? (7 Replies)
Discussion started by: hamon
7 Replies

7. Solaris

Tip: Ldom migration

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)
Discussion started by: mahendra170
1 Replies

8. Shell Programming and Scripting

[Tip] A better echo

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)
Discussion started by: MadeInGermany
2 Replies

9. UNIX for Advanced & Expert Users

[Tip] ptree for Linux

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)
Discussion started by: MadeInGermany
6 Replies
phones(4)                                                          File Formats                                                          phones(4)

NAME
phones - remote host phone number database SYNOPSIS
/etc/phones DESCRIPTION
The file /etc/phones contains the system-wide private phone numbers for the tip(1) program. /etc/phones is normally unreadable, and so may contain privileged information. The format of /etc/phones is a series of lines of the form: <system-name>[ ]*<phone-number>. The system name is one of those defined in the remote(4) file and the phone number is constructed from [0123456789-=*%]. The `=' and `*' characters are indicators to the auto call units to pause and wait for a second dial tone (when going through an exchange). The `=' is required by the DF02-AC and the `*' is required by the BIZCOMP 1030. Comment lines are lines containing a `#' sign in the first column of the line. Only one phone number per line is permitted. However, if more than one line in the file contains the same system name tip(1) will attempt to dial each one in turn, until it establishes a connection. FILES
/etc/phones SEE ALSO
tip(1), remote(4) SunOS 5.10 14 Jan 1992 phones(4)
All times are GMT -4. The time now is 09:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy