Sponsored Content
Full Discussion: using sed to get IP-address
Top Forums Shell Programming and Scripting using sed to get IP-address Post 302248176 by MrC on Friday 17th of October 2008 05:17:27 AM
Old 10-17-2008
A regular expression can be written lax, potentially matching unexpected data, or can be written strictly, matching only exact data. The key is to know what your data looks like and describe it accurately.
MrC
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed: Multiple Commands applied to an address

Trying to write a sed command that applies multiple replacements to a specific address. Need a second pair of eyes I guess cause my syntax appears to be correct (obviously not though) I am getting an error. Any Help would be appreciated! Thanks in advance. sed -f foo envOracle sed: Function... (2 Replies)
Discussion started by: google
2 Replies

2. UNIX for Dummies Questions & Answers

$Variable address in sed

I'm attempting to append a line after a specific address with sed. If I type in the address eg.3 then it will append after the third line. I can't get it to work with a variable though. Does anyone know how to do it please? sed '/3/a\ text' filename :) sed '/\$address/a\ text' filename... (8 Replies)
Discussion started by: Sniper Pixie
8 Replies

3. UNIX for Dummies Questions & Answers

grep or sed help for a word and an IP address

I would like to grab only designates and the IP address next to it. I can also live with client-ip=xx.xx.xx.xx Any help is much appreciated. line to grep or sed: Received-SPF: pass (google.com: domain of support@uhb-hosting.de designates 80.67.28.12 as permitted sender)... (7 Replies)
Discussion started by: tigta09
7 Replies

4. Shell Programming and Scripting

Get Local IP address using Sed, Awk

Hi All, how to get solaris box local ip addresss in variable, using sed or awk utlities. Thanks, Mani Muthu (7 Replies)
Discussion started by: k_manimuthu
7 Replies

5. Shell Programming and Scripting

SED With Regex to extract Email Address

Hi Folks, In my program, I have a variable which consists of multiple lines. i need to use each line as an input. My intention is to extract the email address of the user in each line and use it to process further. The email address could be anywhere in the whole line. But there will be only... (5 Replies)
Discussion started by: ragz_82
5 Replies

6. Shell Programming and Scripting

HELP with awk or sed. Need to replace all IP address by 2

Hi, In a file, I have several time <IP>232.0.1.164</IP> ... <IP>232.0.1.135</IP> I need to replace all the random IP addresses , by 239.0.0.1 and 239.0.0.2 , alternatively. I try this grep "<IP>" tsp.xml | awk '{if(NR % 2)print $0}' | cut -d"<" -f2 | cut -d">" -f2 ... (3 Replies)
Discussion started by: FredMo
3 Replies

7. Solaris

Find and sed for an email address in Solaris 10

in Solaris 10 I am able to run: find . -type f -name "copy*" exec grep example.com {} \; and I get results. but when I try to find and sed: find . -type f -name "copy*" exec sed -e 's/user@example\.com/user2@example\.com' {} \; the command executes correctly but doesn't change... (6 Replies)
Discussion started by: os2mac
6 Replies

8. Shell Programming and Scripting

IP Address Modification through awk/sed

Hi, I have to modify the 2nd and 3rd octet of the IP address through awk/sed. For Example: Given IP is : 10.205.22.254, it should be modified as 10.105.100.254 through awk/sed. Kindly help me on this and let me know if you have any questions. Thanks in advances. (2 Replies)
Discussion started by: kumarbka
2 Replies

9. Shell Programming and Scripting

Sed: -e expression #1, char 16: unterminated address regex

I am trying to grep for a particular text (Do action on cell BL330) in a text file(sample.gz) which is searched in the content filtered by date+timestamp (2016-09-14 01:09:56,796 to 2016-09-15 04:10:29,719) on a remote machine and finally write the output into a output file on a local machine. ... (23 Replies)
Discussion started by: rbadveti
23 Replies

10. UNIX for Beginners Questions & Answers

Sed: -e expression #1, char 20: unterminated address regex

I am trying to add word in last of particular line. the same command syntex is running on prompt. but in bash script give error."sed: -e expression #1, char 20: unterminated address regex" Please help. for i in `cat servername`; do ssh -q -t root@$i sed -i '/simple_allow_groups =/s/$/,... (4 Replies)
Discussion started by: yash_message
4 Replies
switch(n)						       Tcl Built-In Commands							 switch(n)

__________________________________________________________________________________________________________________________________________________

NAME
switch - Evaluate one of several scripts, depending on a given value SYNOPSIS
switch ?options? string pattern body ?pattern body ...? switch ?options? string {pattern body ?pattern body ...?} _________________________________________________________________ DESCRIPTION
The switch command matches its string argument against each of the pattern arguments in order. As soon as it finds a pattern that matches string it evaluates the following body argument by passing it recursively to the Tcl interpreter and returns the result of that evaluation. If the last pattern argument is default then it matches anything. If no pattern argument matches string and no default is given, then the switch command returns an empty string. If the initial arguments to switch start with - then they are treated as options unless there are exactly two arguments to switch (in which | case the first must the string and the second must be the pattern/body list). The following options are currently supported: -exact Use exact matching when comparing string to a pattern. This is the default. -glob When matching string to the patterns, use glob-style matching (i.e. the same as implemented by the string match command). -regexp When matching string to the patterns, use regular expression matching (as described in the re_syntax reference page). | -nocase | Causes comparisons to be handled in a case-insensitive manner. | -matchvar varName | This option (only legal when -regexp is also specified) specifies the name of a variable into which the list of matches found by | the regular expression engine will be written. The first element of the list written will be the overall substring of the input | string (i.e. the string argument to switch) matched, the second element of the list will be the substring matched by the first | capturing parenthesis in the regular expression that matched, and so on. When a default branch is taken, the variable will have | the empty list written to it. This option may be specified at the same time as the -indexvar option. | -indexvar varName | This option (only legal when -regexp is also specified) specifies the name of a variable into which the list of indices referring | to matching substrings found by the regular expression engine will be written. The first element of the list written will be a | two-element list specifying the index of the start and index of the first character after the end of the overall substring of the | input string (i.e. the string argument to switch) matched, in a similar way to the -indices option to the regexp can obtain. | Similarly, the second element of the list refers to the first capturing parenthesis in the regular expression that matched, and | so on. When a default branch is taken, the variable will have the empty list written to it. This option may be specified at the | same time as the -matchvar option. -- Marks the end of options. The argument following this one will be treated as string even if it starts with a -. This is not | required when the matching patterns and bodies are grouped together in a single argument. Two syntaxes are provided for the pattern and body arguments. The first uses a separate argument for each of the patterns and commands; this form is convenient if substitutions are desired on some of the patterns or commands. The second form places all of the patterns and commands together into a single argument; the argument must have proper list structure, with the elements of the list being the patterns and commands. The second form makes it easy to construct multi-line switch commands, since the braces around the whole list make it unnec- essary to include a backslash at the end of each line. Since the pattern arguments are in braces in the second form, no command or vari- able substitutions are performed on them; this makes the behavior of the second form different than the first form in some cases. If a body is specified as "-" it means that the body for the next pattern should also be used as the body for this pattern (if the next pattern also has a body of "-" then the body after that is used, and so on). This feature makes it possible to share a single body among several patterns. Beware of how you place comments in switch commands. Comments should only be placed inside the execution body of one of the patterns, and not intermingled with the patterns. EXAMPLES
The switch command can match against variables and not just literals, as shown here (the result is 2): set foo "abc" switch abc a - b {expr {1}} $foo {expr {2}} default {expr {3}} Using glob matching and the fall-through body is an alternative to writing regular expressions with alternations, as can be seen here (this returns 1): switch -glob aaab { a*b - b {expr {1}} a* {expr {2}} default {expr {3}} } Whenever nothing matches, the default clause (which must be last) is taken. This example has a result of 3: switch xyz { a - b { # Correct Comment Placement expr {1} } c { expr {2} } default { expr {3} } } When matching against regular expressions, information about what exactly matched is easily obtained using the -matchvar option: | switch -regexp -matchvar foo -- $bar { | a(b*)c { | puts "Found [string length [lindex $foo 1]] 'b's" | } | d(e*)f(g*)h { | puts "Found [string length [lindex $foo 1]] 'e's and | [string length [lindex $foo 2]] 'g's" | } | } | SEE ALSO
for(n), if(n), regexp(n) KEYWORDS
switch, match, regular expression Tcl 8.5 switch(n)
All times are GMT -4. The time now is 09:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy