02-22-2010
Quote:
alister can you elaborate on this part of the command what exactly does it do?
index($0,x)
It checks to see if the string you're searching for (stored in the variable x) is present in the current line (stored in $0). If so, index() returns a non-zero value which in AWK is equivalent to a boolean true value. If the string is not found, index() returns zero. If true, it prints out that line (the default action which is implied is "{print $0}".
My post with the awk solutions included two commands; the second negates the return value with a "!", so that it excludes lines that match (what you are doing with sed's d command).
All that said, you're probably best off using the fgrep commands at the end of my previous post.
Cheers,
Alister
This User Gave Thanks to alister For This Post:
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hello
I am new to shell scripting and can anyone tell me how to check if there are any special characters in a file. Can i use grep ?
thanks
susie (2 Replies)
Discussion started by: cramya80
2 Replies
2. Shell Programming and Scripting
Hello,
I have a requirement to search a directory, which contains any number of other directories for file names that contain special characters.
directory structure
DIR__
|__>DIR1
|__>DIR2__
|__>DIR2.1
|__>DIR2.2
|__>DIR3
..
... (8 Replies)
Discussion started by: jerardfjay
8 Replies
3. Shell Programming and Scripting
i'm puzzled....
trying to look for the pattern }"'. but the below code returns to me the message below (pattern is curley queue + dbl qt + sng qt + period)
nawk -v pat="\}\"\'\."'
{
if (match($0, pat)) {
before = substr($0,1,RSTART-1);
... (11 Replies)
Discussion started by: danmauer
11 Replies
4. AIX
Hi,
On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories.
Having said that I am more curious to know how this can be done.
an sample... (3 Replies)
Discussion started by: jerardfjay
3 Replies
5. Shell Programming and Scripting
Hi all,
I have the following lines
<b>A gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text)
<b>B gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text)
<b>J gtwrhwrthwr text hghthwrhtwrtw </b><font color='#06C'>; text text (text)
and I would like to... (5 Replies)
Discussion started by: stinkefisch
5 Replies
6. Shell Programming and Scripting
I'm looking for SED equivalent for grep -w -f. All I want is to search a list of patterns from a file. Also If the pattern doesn't match I do not want "null returned", rather I would prefer some text as place holder say "BLANK LINE" as I intend to process the output file based on line number.
... (1 Reply)
Discussion started by: novice_man
1 Replies
7. Shell Programming and Scripting
Hello All,
I am here again scratching my head on pattern selection with special characters.
I have a large file having around 200 entries and i have to select a single line based on a pattern.
I am able to do that:
Code:
cat mytest.txt | awk -F: '/myregex/ { print $2}'
... (6 Replies)
Discussion started by: usha rao
6 Replies
8. Shell Programming and Scripting
Hi all,
I have a list which I want to search in another file.
I can do that using
grep -f
but the search is failing due to special characters, how do I solve this?
One row in that list is
amino-acid permease inda1 gb|EDU41782.1| amino-acid permease inda1 Input file to be searched... (2 Replies)
Discussion started by: gina.lizar
2 Replies
9. UNIX for Dummies Questions & Answers
Search special characters in a file and replace with meaningful text messages like Hello (2 Replies)
Discussion started by: raka_rjit
2 Replies
10. UNIX for Beginners Questions & Answers
Hello Team,
Any help would be much appreciated for the below scenario:
I have a sed command below where I am trying to replace the contents of 'old_pkey' variable with 'new_pkey' variable in a Soap request file (delete_request.txt). This works fine for regular string values, but this new_pkey... (8 Replies)
Discussion started by: ChicagoBlues
8 Replies
lset(n) Tcl Built-In Commands lset(n)
__________________________________________________________________________________________________________________________________________________
NAME
lset - Change an element in a list
SYNOPSIS
lset varName ?index...? newValue
_________________________________________________________________
DESCRIPTION
The lset command accepts a parameter, varName, which it interprets as the name of a variable containing a Tcl list. It also accepts zero
or more indices into the list. The indices may be presented either consecutively on the command line, or grouped in a Tcl list and pre-
sented as a single argument. Finally, it accepts a new value for an element of varName.
If no indices are presented, the command takes the form:
lset varName newValue
or
lset varName {} newValue
In this case, newValue replaces the old value of the variable varName.
When presented with a single index, the lset command treats the content of the varName variable as a Tcl list. It addresses the index'th
element in it (0 refers to the first element of the list). When interpreting the list, lset observes the same rules concerning braces and
quotes and backslashes as the Tcl command interpreter; however, variable substitution and command substitution do not occur. The command
constructs a new list in which the designated element is replaced with newValue. This new list is stored in the variable varName, and is
also the return value from the lset command.
If index is negative or greater than or equal to the number of elements in $varName, then an error occurs.
The interpretation of each simple index value is the same as for the command string index, supporting simple index arithmetic and indices |
relative to the end of the list.
If additional index arguments are supplied, then each argument is used in turn to address an element within a sublist designated by the
previous indexing operation, allowing the script to alter elements in sublists. The command,
lset a 1 2 newValue
or
lset a {1 2} newValue
replaces element 2 of sublist 1 with newValue.
The integer appearing in each index argument must be greater than or equal to zero. The integer appearing in each index argument must be
strictly less than the length of the corresponding list. In other words, the lset command cannot change the size of a list. If an index
is outside the permitted range, an error is reported.
EXAMPLES
In each of these examples, the initial value of x is:
set x [list [list a b c] [list d e f] [list g h i]]
-> {a b c} {d e f} {g h i}
The indicated return value also becomes the new value of x (except in the last case, which is an error which leaves the value of x
unchanged.)
lset x {j k l}
-> j k l
lset x {} {j k l}
-> j k l
lset x 0 j
-> j {d e f} {g h i}
lset x 2 j
-> {a b c} {d e f} j
lset x end j
-> {a b c} {d e f} j
lset x end-1 j
-> {a b c} j {g h i}
lset x 2 1 j
-> {a b c} {d e f} {g j i}
lset x {2 1} j
-> {a b c} {d e f} {g j i}
lset x {2 3} j
-> list index out of range
In the following examples, the initial value of x is:
set x [list [list [list a b] [list c d]]
[list [list e f] [list g h]]]
-> {{a b} {c d}} {{e f} {g h}}
The indicated return value also becomes the new value of x.
lset x 1 1 0 j
-> {{a b} {c d}} {{e f} {j h}}
lset x {1 1 0} j
-> {{a b} {c d}} {{e f} {j h}}
SEE ALSO
list(n), lappend(n), lindex(n), linsert(n), llength(n), lsearch(n), lsort(n), lrange(n), lreplace(n), string(n) |
KEYWORDS
element, index, list, replace, set
Tcl 8.4 lset(n)