Sponsored Content
Full Discussion: Sed/UNIX help
Top Forums Shell Programming and Scripting Sed/UNIX help Post 302897714 by Don Cragun on Tuesday 15th of April 2014 02:26:44 PM
Old 04-15-2014
\1 in the replacement string in the sed substitute command is replaced by the set of characters matched by expression in the 1st \(expression\) in the basic regular expression used in the sed substitution command's search pattern, \2 is replaced by the set of characters matched by the 2nd \(expression\), and \3 is replaced by the set of characters matched by the 3rd \(expression\).
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using sed in unix

I have a log file with over 500000 lines and I want to use sed command to filter through the file and delete the first 5000 lines. I have tried sed -e '1,5000d' fileA. where d is delete but this does not work. Any ideas ? Regards dodo14 :o (1 Reply)
Discussion started by: dodo14
1 Replies

2. Shell Programming and Scripting

UNIX in the MacIntosh (for sed people)

Hi, I'm trying to use sed to process some files on Macs running OSX. Anyone know anything about Macs and sed? Here's the problem sed 's/^/ /g' test_file > endfile (there are spaces betwen the second and third /, but the forum software compresses them) This should put spaces at... (3 Replies)
Discussion started by: Laurel Maury
3 Replies

3. UNIX for Advanced & Expert Users

unix awk/sed program

i need a sample unix awk/sed program to replace param3 in a file. i have sample file a.dat with the following format/length (week 8, sku 20, store 20 and qty 8). all store id's which end with _2 needs to be replaced with div id 2. all store id's which end with _1 needs to be replaced with div id... (4 Replies)
Discussion started by: mnnarendra
4 Replies

4. Shell Programming and Scripting

sed or unix question

hello, i have a csh file that calls a program and stores the output in a variable. the output is: \*\%VFT\$1\\3 as you can see there is a backslash before every non alphanumeric character. i save this output and then use SED to replace a word in a file with the output that i got. ... (3 Replies)
Discussion started by: davea402
3 Replies

5. Shell Programming and Scripting

sed -i not working in HP unix

hi i want to append the number in each file,but when i ran this command:- sed -i "1i 50" filename its giving error sed: illegal option -- i in HP unix but its working in linux. any advice !!!!!!!!! (6 Replies)
Discussion started by: abhigrkist
6 Replies

6. UNIX for Dummies Questions & Answers

Using sed in unix

Please help on the usage of sed in unix. The questions are below : 1. how to display a particular word in a file using sed 2. how to replace a single letter in a word using sed ex : in a file, all the 'ram' should be replaced by 'Ram' 3. i want to display a particular word from file... (1 Reply)
Discussion started by: nani_ynm
1 Replies

7. UNIX for Advanced & Expert Users

UNIX sed command help

Hi, I am a new student learning about Unix. Can anyone help with the following sed command. What would this command do? sed -n -e '/^s/p' Any help you can provide would be a big help. Thanks in advance! (2 Replies)
Discussion started by: dgigga
2 Replies

8. How to Post in the The UNIX and Linux Forums

Help me in awk or sed in UNIX

I have a fixed length file that looks like a@ a00 a00000 a00 a000000 a00 a0000 a0000 a00000000 a01 a@ a1 a2 a11 a22 a12 a13 a44 a45 a54 a65 a76 a77 a@ a1 a3 a6 a7 a9 a8 a2 a7 a8 a8 a9 a0 b@ b00 b00000 b00... (1 Reply)
Discussion started by: RJG
1 Replies

9. Shell Programming and Scripting

Help me in awk or sed in UNIX

I have a fixed length file a.txt that looks like a@ a00 a00000 a00 a000000 a00 a0000 a0000 a00000000 a01 a@ a1 a2 a11 a22 a12 a13 a44 a45 a54 a65 a76 a77 a@ a1 a3 a6 a7 a9 a8 a2 a7 a8 a8 a9 a0 b@ b00... (7 Replies)
Discussion started by: RJG
7 Replies

10. UNIX for Beginners Questions & Answers

Working with if and sed in UNIX

I have a text file containing multiple lines like password="&test."; password="xyz"; password='write some'; password="&testwrite."; today='o1jan2017'd; ----------------- ------------------ I don't want to replace the string value which are starting with & for Password variable... (3 Replies)
Discussion started by: harshabag
3 Replies
regsub(n)						       Tcl Built-In Commands							 regsub(n)

__________________________________________________________________________________________________________________________________________________

NAME
regsub - Perform substitutions based on regular expression pattern matching SYNOPSIS
regsub ?switches? exp string subSpec ?varName? _________________________________________________________________ DESCRIPTION
This command matches the regular expression exp against string, and either copies string to the variable whose name is given by varName or returns string if varName is not present. (Regular expression matching is described in the re_syntax reference page.) If there is a match, then while copying string to varName (or to the result of this command if varName is not present) the portion of string that matched exp is replaced with subSpec. If subSpec contains a "&" or "", then it is replaced in the substitution with the portion of string that matched exp. If subSpec contains a " ", where n is a digit between 1 and 9, then it is replaced in the substitution with the portion of string that matched the n'th parenthesized subexpression of exp. Additional backslashes may be used in subSpec to prevent special inter- pretation of "&", "", " " and backslashes. The use of backslashes in subSpec tends to interact badly with the Tcl parser's use of back- slashes, so it is generally safest to enclose subSpec in braces if it includes backslashes. If the initial arguments to regsub start with - then they are treated as switches. The following switches are currently supported: -all All ranges in string that match exp are found and substitution is performed for each of these ranges. Without this switch only the first matching range is found and substituted. If -all is specified, then "&" and " " sequences are handled for each sub- stitution using the information from the corresponding match. -expanded Enables use of the expanded regular expression syntax where whitespace and comments are ignored. This is the same as speci- fying the (?x) embedded option (see the re_syntax manual page). -line Enables newline-sensitive matching. By default, newline is a completely ordinary character with no special meaning. With this flag, "[^" bracket expressions and "." never match newline, "^" matches an empty string after any newline in addition to its normal function, and "$" matches an empty string before any newline in addition to its normal function. This flag is equivalent to specifying both -linestop and -lineanchor, or the (?n) embedded option (see the re_syntax manual page). -linestop Changes the behavior of "[^" bracket expressions and "." so that they stop at newlines. This is the same as specifying the (?p) embedded option (see the re_syntax manual page). -lineanchor Changes the behavior of "^" and "$" (the "anchors") so they match the beginning and end of a line respectively. This is the same as specifying the (?w) embedded option (see the re_syntax manual page). -nocase Upper-case characters in string will be converted to lower-case before matching against exp; however, substitutions specified by subSpec use the original unconverted form of string. -start index Specifies a character index offset into the string to start matching the regular expression at. The index value is interpreted | in the same manner as the index argument to string index. When using this switch, "^" will not match the beginning of the line, and A will still match the start of the string at index. index will be constrained to the bounds of the input string. -- Marks the end of switches. The argument following this one will be treated as exp even if it starts with a -. If varName is supplied, the command returns a count of the number of matching ranges that were found and replaced, otherwise the string after replacement is returned. See the manual entry for regexp for details on the interpretation of regular expressions. EXAMPLES
Replace (in the string in variable string) every instance of foo which is a word by itself with bar: regsub -all {mfooM} $string bar string or (using the "basic regular expression" syntax): regsub -all {(?b)<foo>} $string bar string Insert double-quotes around the first instance of the word interesting, however it is capitalized. regsub -nocase {yinterestingy} $string {"&"} string Convert all non-ASCII and Tcl-significant characters into u escape sequences by using regsub and subst in combination: # This RE is just a character class for everything "bad" set RE {[][{};#\$su0080-uffff]} # We will substitute with a fragment of Tcl script in brackets set substitution {[format \\u%04x [scan "\&" %c]]} # Now we apply the substitution to get a subst-string that # will perform the computational parts of the conversion. set quoted [subst [regsub -all $RE $string $substitution]] SEE ALSO
regexp(n), re_syntax(n), subst(n), string(n) | KEYWORDS
match, pattern, quoting, regular expression, substitute Tcl 8.3 regsub(n)
All times are GMT -4. The time now is 03:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy