06-28-2007
thnx a lot m8 u great!
look what im trying to do:
#!bin/bash
file=$1
read myVar
(echo '0a'; echo '$myVar'; echo '.'; echo 'wq') | ed -s $1
i want to create a script which always put a string at the very top.
but why when i run it instead of displaying a tex the output is $myVar
eg:
$myVar
mmmm....
Hi everybody!!!!
seems to me
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need to add a new lines with certain data, to an existing file, every 5 lines in the file.
There is no way to find any distinct charater pattern so
I will have to do a line count and then insert the new line.
I think using awk or sed is what I need to do.
Any help is appreciated.
Kunder (2 Replies)
Discussion started by: kunder
2 Replies
2. Shell Programming and Scripting
Hi,
I have tried many times to add the string into the first line of the file or the middle of the file but could not find the solution.
I first tried by
$echo "paki" >> file
This code only append paki string at the end of file "file" but how can i add this "paki" into the first line or... (5 Replies)
Discussion started by: ali hussain
5 Replies
3. Shell Programming and Scripting
Can anyone help me pls? I want to add a text into the middle of file.
I've writtenthe following script
text to add="$1"
file="$2"
lines=$(wc -l $2)
half_lines=$(expr $lines / 2)
head -$half_lines $2 > temp
echo "text to add" >> temp
((half_lines=$half_lines + 1))
tail -$half_lines $2... (6 Replies)
Discussion started by: relle
6 Replies
4. Shell Programming and Scripting
I've got a configuration file that is filled with xml text statements for example:
<...../>
<...../>
<...../>
<data id="java-options" value="-server -Djava.security.policy..../>
<...../>
<...../>
<...../>
I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies
5. Shell Programming and Scripting
I am trying to strip out certain characters from a string on both (left & right) sides. For example, line=see@hear|touch, i only want to echo the "hear" part. Well i have tried this approach:
line=see@hear|touch
templine=${line#*@} #removed "see@"
echo ${templine%%\|*} #removed... (4 Replies)
Discussion started by: mcoblefias
4 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I want to write a script that takes a file and a string as params and adds the string to the middle line of the file. Also, I want to output the results back to the original file passed without using temp files.
I am very much new to UNIX so this is all a little like black magic to me at... (15 Replies)
Discussion started by: Chiefos
15 Replies
7. UNIX for Dummies Questions & Answers
Hello all!
I'm trying to put together a small script that will take in a file name and attach a datestamp to the end of it (but before the file type extension).
To illustrate...
Before:
filename.txt
anotherfilename.txt
After:
filename_20090724.txt
anotherfilename_20090724.txt
... (7 Replies)
Discussion started by: jisoo411
7 Replies
8. Linux
my file input is with tab as delimiter, and in every line, there would be a skip of line with an unexcepted newline breaker. I'd like to remove this \n and put the information in the same line.
INPUT
a1 b1b2 c1
c2 d1
a2 b3 c3 d4
OUTPUT
a1 b1b2 c1c2 ... (9 Replies)
Discussion started by: kinkichin
9 Replies
9. UNIX for Dummies Questions & Answers
Hi Folks!
I hope you can help me figure this out. I need to print a record which contains the contents of a config file. The contents of the config file should be found within the 21st and the 30th position of the fixed width reference file.
Config File:
aaaa
bbbb
cccc
Reference... (3 Replies)
Discussion started by: kokoro
3 Replies
10. UNIX for Beginners Questions & Answers
My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data.
... (7 Replies)
Discussion started by: chandrath
7 Replies
upvar(n) Tcl Built-In Commands upvar(n)
__________________________________________________________________________________________________________________________________________________
NAME
upvar - Create link to variable in a different stack frame
SYNOPSIS
upvar ?level? otherVar myVar ?otherVar myVar ...?
_________________________________________________________________
DESCRIPTION
This command arranges for one or more local variables in the current procedure to refer to variables in an enclosing procedure call or to
global variables. Level may have any of the forms permitted for the uplevel command, and may be omitted if the first letter of the first
otherVar is not # or a digit (it defaults to 1). For each otherVar argument, upvar makes the variable by that name in the procedure frame
given by level (or at global level, if level is #0) accessible in the current procedure by the name given in the corresponding myVar argu-
ment. The variable named by otherVar need not exist at the time of the call; it will be created the first time myVar is referenced, just
like an ordinary variable. There must not exist a variable by the name myVar at the time upvar is invoked. MyVar is always treated as the
name of a variable, not an array element. An error is returned if the name looks like an array element, such as a(b). OtherVar may refer
to a scalar variable, an array, or an array element. Upvar returns an empty string.
The upvar command simplifies the implementation of call-by-name procedure calling and also makes it easier to build new control constructs
as Tcl procedures. For example, consider the following procedure:
proc add2 name {
upvar $name x
set x [expr {$x + 2}]
}
If add2 is invoked with an argument giving the name of a variable, it adds two to the value of that variable. Although add2 could have
been implemented using uplevel instead of upvar, upvar makes it simpler for add2 to access the variable in the caller's procedure frame.
namespace eval is another way (besides procedure calls) that the Tcl naming context can change. It adds a call frame to the stack to rep-
resent the namespace context. This means each namespace eval command counts as another call level for uplevel and upvar commands. For
example, info level 1 will return a list describing a command that is either the outermost procedure call or the outermost namespace eval
command. Also, uplevel #0 evaluates a script at top-level in the outermost namespace (the global namespace).
If an upvar variable is unset (e.g. x in add2 above), the unset operation affects the variable it is linked to, not the upvar variable.
There is no way to unset an upvar variable except by exiting the procedure in which it is defined. However, it is possible to retarget an
upvar variable by executing another upvar command.
TRACES AND UPVAR
Upvar interacts with traces in a straightforward but possibly unexpected manner. If a variable trace is defined on otherVar, that trace
will be triggered by actions involving myVar. However, the trace procedure will be passed the name of myVar, rather than the name of oth-
erVar. Thus, the output of the following code will be "localVar" rather than "originalVar":
proc traceproc { name index op } {
puts $name
}
proc setByUpvar { name value } {
upvar $name localVar
set localVar $value
}
set originalVar 1
trace variable originalVar w traceproc
setByUpvar originalVar 2
If otherVar refers to an element of an array, then variable traces set for the entire array will not be invoked when myVar is accessed (but
traces on the particular element will still be invoked). In particular, if the array is env, then changes made to myVar will not be passed
to subprocesses correctly.
EXAMPLE
A decr command that works like incr except it subtracts the value from the variable instead of adding it:
proc decr {varName {decrement 1}} {
upvar 1 $varName var
incr var [expr {-$decrement}]
}
SEE ALSO
global(n), namespace(n), uplevel(n), variable(n)
KEYWORDS
context, frame, global, level, namespace, procedure, variable
Tcl upvar(n)