could u pls expain to me what means the expr 's/^/newBeginning/' ?
doing 'man sed' yields:
Code:
s/regular expression/replacement/flags
____________________________________________________________
Substitute the replacement string for
instances of the regular expression in the
pattern space. Any character other than
backslash or newline can be used instead of a
slash to delimit the RE and the replacement.
Within the RE and the replacement, the RE del-
imiter itself can be used as a literal charac-
ter if it is preceded by a backslash.
____________________________________________________________
An ampersand (&) appearing in the replacement
will be replaced by the string matching the
RE. The special meaning of & in this context
can be suppressed by preceding it by
backslash. The characters \n, where n is a
digit, will be replaced by the text matched by
the corresponding backreference expression.
For each backslash (\) encountered in scanning
replacement from beginning to end, the follow-
ing character loses its special meaning (if
any). It is unspecified what special meaning
is given to any character other than &, \ or
digits.
Greetings.
I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file.
I'm struggling to see how each line can be... (5 Replies)
Hi All,
I have a file like this,
data1,data2,,,data5,data6.
i want to write a shell script to replace data3 with "/example/string". which means my data file should look like this .
data1,data2,example/string],,data5,data6.
Could you guys help me to get a sed command or any other command... (8 Replies)
hello mighty all
there is a line of 50 words and i need to take a random number of words from the beginning (20 words for example) then put my word then add other 10 words from the continue then add another my special word then add 20 words till the end..
my own knowledge base can say it is... (12 Replies)
Hi,
I am new to shell scripting. I need a bash shell scripts which search and grep a parameter value from input.txt file and insert it in between two semicolon of second line of output.txt file.
For example
The shell script search an IP address as parameter value from input.txt ... (2 Replies)
Hello,
I am looking to automate a task - which is updating an existing access control instruction of a server and making sure that the attributes defined in the instruction is in sorted order. The instructions will be of a specific syntax.
For example lets assume below listed is one of an... (6 Replies)
Hi,
I have a text file with one line having few words separated by space and I need to insert another word on "n"th column/field so that previous word should shift right (to n+1st column). how can I do that?
It seems we can do using awk but unable to figure out.
Please advise, thanks!
... (11 Replies)
Hi All,
Hope you guys had a wonderful weekend
I have a scenario where in which I have to read a file line by line
and check for few words before redirecting to a file
I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
I have a file: file.txt, which contains the following data in it.
This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt
My name is not Karl, my name is Karl Joey
What is your name?
Do you know your name and... (3 Replies)
I have a test file that I want to read and insert only certain lines into the
the table based on a filter.
1. Rread the log file 12 Hours back Getdate() -12 Hours
2. Extract the following information on for lines that say "DUMP is
complete"
A. Date
B. Database Name
C.... (2 Replies)
Hi All,
I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise
My intention is to insert a line of text after 13th line of every file inside a particular directory.
While trying to do it for a single file , i am using sed
sed '3 i this is the 4th line' filename
sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies
LEARN ABOUT OPENDARWIN
regsub
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 por-
tion of string that matched the n-th parenthesized subexpression of exp. Additional backslashes may be used in subSpec to prevent special
interpretation of ``&'' or `` '' or ``
'' or backslash. The use of backslashes in subSpec tends to interact badly with the Tcl parser's
use of backslashes, so it's 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
substitution 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. 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.
SEE ALSO
regexp(n), re_syntax(n)
KEYWORDS
match, pattern, regular expression, substitute
Tcl 8.3 regsub(n)