My String variable is holding value as - abc"def
I want to replce " with \"
I tried with awk :
echo $var | awk '{gsub(/"/,"\"");print}'
and I am getting an error, `)' is not expected. (1 Reply)
hi
I have a variable like
k=$DESTDIR/$PKG/$VERSION
I want to replace each $ in string k with say "XXX".
so that k becomes like this "XXXDESTDIR/XXXPKG/XXXVERSION"
when I use echo $k | sed -e "s/\$/XXX" it actually passes expanded of variables $DESTDIR, $PKG and $VERSION to sed.
... (10 Replies)
Input file - tmp
<begin>
./00003/
./00004/
<end>
I would like to replace "." with the value of pwd
so that the output will look like
/dev/project/00003/
t=`pwd`
sed -e "s/\./$t/g" tmp > tmp1;
The above piece of code is not working. Appreciate your help. (4 Replies)
Hi,
If I have a variable
var1 ='TH 12/1234'
How can I set this too in a script
var1 ='TH 12~1234'
Bearing in mind "/" might be in a difference place each time and that the "/" might not even exist each time
the variable is set.
Thanks (3 Replies)
All I want to do is replace the 2nd line in a file with a variable, eg,
var=xxx
the file 'test' containing:
aaa
bbb
ccc
replace bbb with xxx
aaa
xxx
ccc
I had it working with sed on a redhat machine, but it doesn't work on a mac machine. (4 Replies)
Hi guys
In my shell script I have a variable that contains a string that contains the current time.
I want to replace the spaces and colons in the value with underscores.
TIME=`date`
echo $TIME
gives me: Thu Sep 24 16:40:53 BST 2009
I want it to show:... (4 Replies)
Simple enough problem I think, I just can't seem to get it right.
The below doesn't work as intended, it's just a function defined in a much larger script:
CheckValues() {
for field in \
Group_ID \
Group_Title \
Rule_ID \
Rule_Severity \
... (2 Replies)
Hello All,
Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....?
I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping
through a string containing some of these "Illegal Characters". Now... (5 Replies)
Hi All,
I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies
LEARN ABOUT OSX
lreplace
lreplace(n) Tcl Built-In Commands lreplace(n)
__________________________________________________________________________________________________________________________________________________NAME
lreplace - Replace elements in a list with new elements
SYNOPSIS
lreplace list first last ?element element ...?
_________________________________________________________________DESCRIPTION
lreplace returns a new list formed by replacing one or more elements of list with the element arguments. first and last are index values |
specifying the first and last elements of the range to replace. The index values first and last are interpreted the same as index values |
for the command string index, supporting simple index arithmetic and indices relative to the end of the list. 0 refers to the first ele- |
ment of the list, and end refers to the last element of the list. If list is empty, then first and last are ignored.
If first is less than zero, it is considered to refer to before the first element of the list. For non-empty lists, the element indicated
by first must exist or first must indicate before the start of the list.
If last is less than first, then any specified elements will be inserted into the list at the point specified by first with no elements
being deleted.
The element arguments specify zero or more new arguments to be added to the list in place of those that were deleted. Each element argu-
ment will become a separate element of the list. If no element arguments are specified, then the elements between first and last are sim-
ply deleted. If list is empty, any element arguments are added to the end of the list.
EXAMPLES
Replacing an element of a list with another:
% lreplace {a b c d e} 1 1 foo
a foo c d e
Replacing two elements of a list with three:
% lreplace {a b c d e} 1 2 three more elements
a three more elements d e
Deleting the last element from a list in a variable:
% set var {a b c d e}
a b c d e
% set var [lreplace $var end end]
a b c d
A procedure to delete a given element from a list:
proc lremove {listVariable value} {
upvar 1 $listVariable var
set idx [lsearch -exact $var $value]
set var [lreplace $var $idx $idx]
}
SEE ALSO
list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), lset(n), lrange(n), lsort(n), string(n) |
KEYWORDS
element, list, replace
Tcl 7.4 lreplace(n)