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
PPIx::Regexp::Token(3)					User Contributed Perl Documentation				    PPIx::Regexp::Token(3)

NAME
PPIx::Regexp::Token - Base class for PPIx::Regexp tokens. SYNOPSIS
use PPIx::Regexp::Dumper; PPIx::Regexp::Dumper->new( 'qr{foo}' )->print(); INHERITANCE
"PPIx::Regexp::Token" is a PPIx::Regexp::Element. "PPIx::Regexp::Token" is the parent of PPIx::Regexp::Token::Assertion, PPIx::Regexp::Token::Backtrack, PPIx::Regexp::Token::CharClass, PPIx::Regexp::Token::Code, PPIx::Regexp::Token::Comment, PPIx::Regexp::Token::Control, PPIx::Regexp::Token::Greediness, PPIx::Regexp::Token::GroupType, PPIx::Regexp::Token::Literal, PPIx::Regexp::Token::Modifier, PPIx::Regexp::Token::Operator, PPIx::Regexp::Token::Quantifier, PPIx::Regexp::Token::Reference, PPIx::Regexp::Token::Structure, PPIx::Regexp::Token::Unknown, PPIx::Regexp::Token::Unmatched and PPIx::Regexp::Token::Whitespace. DESCRIPTION
This class represents the base of the class hierarchy for tokens in the PPIx::Regexp package. METHODS
This class provides no public methods beyond those provided by its superclass. SUPPORT
Support is by the author. Please file bug reports at <http://rt.cpan.org>, or in electronic mail to the author. AUTHOR
Thomas R. Wyant, III wyant at cpan dot org COPYRIGHT AND LICENSE
Copyright (C) 2009-2013 by Thomas R. Wyant, III This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. perl v5.16.3 2014-06-10 PPIx::Regexp::Token(3)
All times are GMT -4. The time now is 06:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy