Sponsored Content
Full Discussion: Help with sed ( & )
Top Forums Shell Programming and Scripting Help with sed ( & ) Post 302529891 by radoulov on Saturday 11th of June 2011 03:06:59 AM
Old 06-11-2011
Because [a-z,/]* matches 0 or more occurrences of [a-z,/] (i.e. it matches a null string too).

Depending on your sed version, you could try the following ones:

Code:
% sed 's/^[a-z,/][a-z,/]*/( & )/' infile
( cool )
( change )
Frinto Francis
Frinto cool
( change ) Attitude
( /usr/bin )

Code:
% sed 's/^[a-z,/]\+/( & )/' infile
( cool )
( change )
Frinto Francis
Frinto cool
( change ) Attitude
( /usr/bin )

As you see, you need to anchor (^) the pattern too, otherwise you'll get a different result:

Code:
% sed 's/[a-z,/][a-z,/]*/( & )/' infile 
( cool )
( change )
F( rinto ) Francis
F( rinto ) cool
( change ) Attitude
( /usr/bin )

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed & awk help...

I have a question. Take the following statement awk -F\| '{print $21}' testfile | sed 's/\//\\/g' > newfile This will grab the 21st column of a | delimited text file, replace the forward slashes "/" , with back slashes "\", and redirect the output newfile. Now, how do I get the output... (4 Replies)
Discussion started by: shimb0
4 Replies

2. Shell Programming and Scripting

cp & sed error

Hi, Below is a small piece of my Korn shell script - what i am trying to do is substitute all occurrences of the word given by the ${src} parameter with the word given by the ${dest} parameter in that particular textfile. But i get the errors below... for i in `ls... (19 Replies)
Discussion started by: n8575
19 Replies

3. Shell Programming and Scripting

sed, date and /&

Hi, $ echo 1 titi | sed -e "s/1/$(echo \&)/" 1 titi but $ echo 1 titi | sed -e "s/1/$(date \&)/" date: invalid date `&' titi how can i do for handle '\&' with date ? Thx (7 Replies)
Discussion started by: sncr24
7 Replies

4. Shell Programming and Scripting

New to Sed & Awk

How do I grab the first 10 characters of a line and append it to another empty file? (7 Replies)
Discussion started by: xgringo
7 Replies

5. Shell Programming and Scripting

sed & awk

Hi. I'm going to learn scripting and i have the following topics on the list: sed, awk, shell scripting, perl. My question is, whehter i should learn sed and awk? Aren't this tools outdated? Although i see that GNU upgrade it's versions of these tools from time to time. And, the next... (9 Replies)
Discussion started by: kukuruku
9 Replies

6. Shell Programming and Scripting

Help, | ! & [ ^ in sed

Hi,everyone: I'm new to shell, and I'm confued with some script: ssum=`echo "$lsum" | sed 's|!|\\\\!|g'` line1=`echo "$line" | sed 's!\!\\\]!g'` line3=`echo "$line2" | sed 's!\&!\\\&!g'` sed "s^${line3}^${newline3}^g" ${TIER4FILE} > ${TMP_TIER4FILE} In the first three lines,... (5 Replies)
Discussion started by: mycoy
5 Replies

7. Shell Programming and Scripting

sed & areas respectively sed & pyramiding

Hello everyone, i wonder if someone could give me an advice regarding the following problem using sed. Given ist a structure as shown below: <aaa>text1<b>text2</b>text3<c>text4</c>text5</aaa> Now I want to change the outer tag from "aaa" to "new" and replace all tags inside the outer tags... (4 Replies)
Discussion started by: Donaldinho
4 Replies

8. UNIX for Dummies Questions & Answers

awk & sed

Hi, Can anyone let me know the difference between awk and sed utilities in Unix? Many thanks. (2 Replies)
Discussion started by: venkatesht
2 Replies

9. UNIX for Beginners Questions & Answers

sed pattern &

Hi, I can't seem to understand what the sed and & do.. Why is the set of numbers appear twice ? how the command really work ? echo "123 abc" | sed 's/*/& www &/' Output: 123 www 123 abc (3 Replies)
Discussion started by: uniran
3 Replies

10. UNIX for Beginners Questions & Answers

Echo "abc" | sed - r 's/a/&_&/

I want to know the working of & here step by step using sed command. (1 Reply)
Discussion started by: Preeti07
1 Replies
Tcl_StringMatch(3)					      Tcl Library Procedures						Tcl_StringMatch(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_StringMatch, Tcl_StringCaseMatch - test whether a string matches a pattern SYNOPSIS
#include <tcl.h> int Tcl_StringMatch(str, pattern) int Tcl_StringCaseMatch(str, pattern, flags) ARGUMENTS
const char *str (in) String to test. const char *pattern (in) Pattern to match against string. May contain special characters from the set *?[]. int flags (in) OR-ed combination of match flags, currently only TCL_MATCH_NOCASE. 0 specifies a case-sensitive search. _________________________________________________________________ DESCRIPTION
This utility procedure determines whether a string matches a given pattern. If it does, then Tcl_StringMatch returns 1. Otherwise Tcl_StringMatch returns 0. The algorithm used for matching is the same algorithm used in the string match Tcl command and is similar to the algorithm used by the C-shell for file name matching; see the Tcl manual entry for details. In Tcl_StringCaseMatch, the algorithm is the same, but you have the option to make the matching case-insensitive. If you choose this (by passing TCL_MATCH_NOCASE), then the string and pattern are essentially matched in the lower case. KEYWORDS
match, pattern, string Tcl 8.5 Tcl_StringMatch(3)
All times are GMT -4. The time now is 08:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy