What about using awk in this case? ---------- Post updated at 21:33 ---------- Previous update was at 21:25 ----------
And if you want to use sed, try
The awk solution gives me everything I need, except it is inserting an unwanted space where we break between quoted text and field references.
the sed solution eliminates the space problem (as well as not having to escape a bunch of quotes in the standard text), but my example was a bit more simple than reality, and I'm not bridging the gap.
Let's say I start with file myfile.txt
abc def ghi
I need to get SOMECANNEDTEXTabcSOMEMORETEXT1STILLMORETEXT SOMECANNEDTEXTdefSOMEMORETEXT2STILLMORETEXT SOMECANNEDTEXTghiSOMEMORETEXT3STILLMORETEXT
Note that the line number is appended at the end of SOMEMORETEXT
I appreciate the help. I'm learning a lot here but still having trouble getting my head wrapped around some of it.
I'm needing to add a "hour:min" to the end of each line in a document. The document in this case is only going to be one line.
if this inserts it at the end, what needs to be changed to add something at the end...
/bin/echo "%s/^/$filler/g\nwq!" | ex -s $oFile
Thank you... (2 Replies)
Hi Guys/Gals,
I have a log file that is updated once every few seconds and I am looking for a way to speed up one of my scripts.
Basically what I am trying to do is grep through a text file from start to finish once. Then each subsequent grep starts at the last line of the previous grep to... (4 Replies)
Hi,
I have 24 .dat files something like below. The file name starts with “abc” followed by two digit month and two digit year. Is there a way to grab the month and year from each filename and append it to the end of each line. Once this is done I want to combine all the files into file... (1 Reply)
Hi
I have few files. For some files the cursor is at the end of last line. For other files, cursor is at the new line at the end.
I want to bring the cursor down to next line for the files that are having cursor at the end of last line
In otherwords, I want to introduce a blank line at the... (5 Replies)
I have 2 files which contains the following lines
file1.txt
line4
line5
line6
file2.txt
line1
line2
line3
When i execute a script , I want my file2.txt will looks like this:
line1
line2
line3
line4
line5 (2 Replies)
sed '$a\
hello' books
hi i am trying to use sed to append hello to the end of the file books, but for some reason i can't get it work. It keeps sayin command garbled. Anyone know what I'm doing wrong. this is in a ksh script as well. (3 Replies)
Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed.
Say I want to print all occurrences of red starting at line 3 to the end of file.
EXAMPLE FILE:
red
green
red
red... (1 Reply)
Hello Everyone,
I need a help from experts of this community regarding one of the issue that I am facing with shell scripting.
My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line.
The... (20 Replies)
Hi,
I want to add a text to the end of the specific line in a file. Now my file looks like this:
999
111
222
333
111
444
I want to add the string " 555" to the end of the first line contaning 111. Moreover, I want to insert a newline after this line containg the "000" string. The... (8 Replies)
Hello All,
I have file a.txt
I want to add a counter loop at the end of each line in a file
ill explain:
i have a site h**p://test.test=Elite#1
i want to add a a counter to the number at the end of the file, that it will be like this
urlLink//test.test=Elite#1
urlLink//test.test=Elite#2... (3 Replies)
Discussion started by: nexsus
3 Replies
LEARN ABOUT OPENDARWIN
subst
subst(n) Tcl Built-In Commands subst(n)
__________________________________________________________________________________________________________________________________________________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(n), eval(n), break(n), continue(n)
KEYWORDS
backslash substitution, command substitution, variable substitution
Tcl 7.4 subst(n)