Okay, I have a script right now that is made to search through a file and replace certain strings with a new one. The format to execute is "/subst <replacethis> <withthis> <filename>" and it only updates the file IF changes are made (in order to preserve the time it was made/last modified). I have this working 100% right now, but the next step is to edit the script so that it is possible for users to do "/subst <replacethis> <withthis> <filename> <filename2> <filename3> <filenamex>" as high as they want. If anyone can point me in the right direction of methods to do this or simply fix it for me, I would be very greatful.
Here is my current script:
Thanks in advance for anyone that can help!
Hi guys, I hope you can help me with my problem.
I have a text file that contains lines like this:
78 ANGELO -809.05
79 ANGELO2 -5,000.06
I need to find all occurences of amounts that are negative and replace them with x's
78 ANGELO xxxxxxx
79... (4 Replies)
Hi,
Let me explain the situation.
There are many files in a directory and its sub-directories that conatin the string pattern "pa". I want to replace all such instances with the pattern "pranavagarwal"
doing a
grep "pa" `ls`
does give me all the instances of the occurence of that... (3 Replies)
Hi
I have a text file which contains the following.
AAA,BBB,CCC,DDD
AAA,BBB,CCC,DDD
AAA,BBB,CCC,DDD
How can I replace all CCC with 888, with other contents inside the file remain unchange? Please advice
Desired output:
AAA,BBB,888,DDD
AAA,BBB,888,DDD
AAA,BBB,888,DDD (1 Reply)
Hi I am new to shell scripting but i manage to do some simple things.
I am trying to replace a string in one file. I am using sed to replace but it is not permanently writing to the file, rather it is temporary. I want to know whether is there any another method to replace a string in a file... (7 Replies)
I have one string
string1=user/password:IP_ADDR:Directory
I need to replace string1 value like store into string2
string2=user password:IP_ADDR:Directory
i.e replace "/" character by '<space>' character
But i wouldn't use any file in the meantime.
Please help me......................... (6 Replies)
I posted this issue a week or so ago and I still cant get the script to work. Here is what I have so far and what Im trying to do.
#!/bin/ksh
old="$1"
new="$2"
file=$3
grep $1 $3 > /dev/null
if ;then
cp $3 ${3}.bak
sed "s/$1/$2/g" $3 > ${3}~
mv ${3}~ ${3}
fithe script is... (5 Replies)
Hi All,
I have below file which has data in below format.
#$ | AB_100
| AB_300
()| AB_4
@*(% | AB-789
i want o/p as below format.
| AB_100
| AB_300
| AB_4
| AB-789
So here there is no standard format.
How we can achieve the same in unix ?
Regards, (3 Replies)
Dear Friends,
I want to replace following line with given line.
It should grep/search following string in a file (input.txt)
M/M SRNO: 000M/6200-0362498 COSMETIC PRO MALE FEMALE
Once found it should replace it to following string.
T_DLHNNO: 000M/6200-0362498 ... (7 Replies)
Hi,
I have a text file where all records come in one line (single line file), each record starts with 'BUCH' and ends with '@&' and if data is not there we get space instead. between '@&' and next record there might be some spaces, now I want to remove those spaces between '@&' and 'BUCH'.
... (4 Replies)
Hi,
Using the following command, I can only get rid of the last extension from my input file name:
parallel command '>' {.}.output ::: my.input.file
The output file is "my.input.output"
How can I get rid of the last two extensions of my input file name, so that end up with "my.output"?... (4 Replies)
Discussion started by: forU
4 Replies
LEARN ABOUT OPENSOLARIS
subst
subst(1T) Tcl Built-In Commands subst(1T)__________________________________________________________________________________________________________________________________________________NAME
subst - Perform backslash, command, and variable substitutions
SYNOPSIS
subst ?-nobackslashes? ?-nocommands? ?-novariables? string
_________________________________________________________________DESCRIPTION
This command performs variable substitutions, command substitutions, and backslash substitutions on its string argument and returns the
fully-substituted result. The substitutions are performed in exactly the same way as for Tcl commands. As a result, the string argument
is actually substituted twice, once by the Tcl parser in the usual fashion for Tcl commands, and again by the subst command.
If any of the -nobackslashes, -nocommands, or -novariables are specified, then the corresponding substitutions are not performed. For
example, if -nocommands is specified, command substitution is not performed: open and close brackets are treated as ordinary characters
with no special interpretation.
Note that the substitution of one kind can include substitution of other kinds. For example, even when the -novariables option is speci- |
fied, command substitution is performed without restriction. This means that any variable substitution necessary to complete the command |
substitution will still take place. Likewise, any command substitution necessary to complete a variable substitution will take place, even |
when -nocommands is specified. See the EXAMPLES below. |
If an error occurs during substitution, then subst will return that error. If a break exception occurs during command or variable substi- |
tution, the result of the whole substitution will be the string (as substituted) up to the start of the substitution that raised the excep- |
tion. If a continue exception occurs during the evaluation of a command or variable substitution, an empty string will be substituted for |
that entire command or variable substitution (as long as it is well-formed Tcl.) If a return exception occurs, or any other return code is |
returned during command or variable substitution, then the returned value is substituted for that substitution. See the EXAMPLES below. |
In this way, all exceptional return codes are ``caught'' by subst. The subst command itself will either return an error, or will complete |
successfully.
EXAMPLES
When it performs its substitutions, subst does not give any special treatment to double quotes or curly braces (except within command sub-
stitutions) so the script
set a 44
subst {xyz {$a}}
returns ``xyz {44}'', not ``xyz {$a}'' and the script |
set a "p} q {r" |
subst {xyz {$a}} |
return ``xyz {p} q {r}'', not ``xyz {p} q {r}''. |
When command substitution is performed, it includes any variable substitution necessary to evaluate the script. |
set a 44 |
subst -novariables {$a [format $a]} |
returns ``$a 44'', not ``$a $a''. Similarly, when variable substitution is performed, it includes any command substitution necessary to |
retrieve the value of the variable. |
proc b {} {return c} |
array set a {c c [b] tricky} |
subst -nocommands {[b] $a([b])} |
returns ``[b] c'', not ``[b] tricky''. |
The continue and break exceptions allow command substitutions to prevent substitution of the rest of the command substitution and the rest |
of string respectively, giving script authors more options when processing text using subst. For example, the script |
subst {abc,[break],def} |
returns ``abc,'', not ``abc,,def'' and the script |
subst {abc,[continue;expr 1+2],def} |
returns ``abc,,def'', not ``abc,3,def''. |
Other exceptional return codes substitute the returned value |
subst {abc,[return foo;expr 1+2],def} |
returns ``abc,foo,def'', not ``abc,3,def'' and |
subst {abc,[return -code 10 foo;expr 1+2],def} |
also returns ``abc,foo,def'', not ``abc,3,def''.
SEE ALSO Tcl(1T), eval(1T), break(1T), continue(1T)KEYWORDS
backslash substitution, command substitution, variable substitution
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+--------------------+-----------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+--------------------+-----------------+
|Availability | SUNWTcl |
+--------------------+-----------------+
|Interface Stability | Uncommitted |
+--------------------+-----------------+
NOTES
Source for Tcl is available on http://opensolaris.org.
Tcl 7.4 subst(1T)