Sponsored Content
Top Forums Shell Programming and Scripting awk : match the string and string with the quotes : Post 302813589 by rveri on Monday 27th of May 2013 04:21:07 PM
Old 05-27-2013
Don, Thanks it worked with grep as you have mentioned:

---------- Post updated at 04:21 PM ---------- Previous update was at 04:19 PM ----------

Also figured out it using variable like : L=lan3 :

Code:
grep -E '('$L'$)|('$L'"$)' file1

INTERFACE_NAME[0]="lan3"
INTERFACE_NAME[10]=lan3


Using awk:
Code:
# L=lan3 ; awk -F'=' -v l1=$L '{for(i=1;i<=NF;i++) if(($i~/'$L'$/)||($i~/'$L'"$/)) print $0}' file1
INTERFACE_NAME[0]="lan3"
INTERFACE_NAME[10]=lan3

Thanks for the help.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how can awk match multi pattern in a string

Hi all, I need to category the processes in my system with awk. And for now, there are several command with similar name, so i have to match more than one pattern to pick it out. for instance: binrundb the string1, 2 & 3 may contain word, number, blank or "/". The "bin" should be ahead "rundb"... (5 Replies)
Discussion started by: sleepy_11
5 Replies

2. Shell Programming and Scripting

Awk:Find length of string omitting quotes

Hi , I have a file named "sample" having the data as follows. "663005487","USD",0,1,"NR" If i give like a=`awk -F ',' '{printf length($2)}' sample` (Trying to find length of second field)I should get the output for the above as 3 (Omitting double quotes) not 5. How to do this..... (2 Replies)
Discussion started by: jayakumarrt
2 Replies

3. Shell Programming and Scripting

How can I match lines with just one occurance of a string in awk?

Hi, I'm trying to match records using awk which contain only one occurance of my string, I know how to match one or more (+) but matching only one is eluding me without developing some convoluted bit of code. I was hoping there would be some simple pattern matching thing similar to '+' but... (9 Replies)
Discussion started by: jonathanm
9 Replies

4. Shell Programming and Scripting

How to get part of string in awk from match

Hi, Im an awk noob and I am having trouble trying to get matches. Here is my script: #!/bin/gawk -f BEGIN {} $0 ~ /<a href=".*">.*<\/a>/{print} Ideally I want to be able to get the actual link and print it. In PHP you can do preg_replace and get the match you want by using \\1 where 1... (2 Replies)
Discussion started by: adsyuk
2 Replies

5. Shell Programming and Scripting

AWK break string into fields + pattern match

I am trying to break a string into separate fields and print the field that matches a pattern. I am using awk at the moment and have gotten this far: awk '{for(i=1;i<=NF;++i)print "\t" $i}' longstring This breaks the string into fields and prints each field on a separate line. I want to add... (2 Replies)
Discussion started by: Moxy
2 Replies

6. Shell Programming and Scripting

match string exactly with awk/sed

Hi all, I have a list that I would like to parse with awk/sed. The list is contains entries such as: JournalTitle: Biochemistry JournalTitle: Biochemistry and cell biology = Biochimie et biologie cellulaire JournalTitle: Biochemistry and experimental biology JournalTitle: Biochemistry and... (6 Replies)
Discussion started by: euval
6 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. UNIX for Dummies Questions & Answers

awk for trimming a string up to the first, then second, then third... match

Hi ! With awk, I would need to trim a string from the beginning up to the first occurrence of "1", then from the beginning up to the second occurrence of "1", then from the beginning up to the third, then the fourth...., then the last occurrence of "1". input: 1aaa1bb1ccccccc dd1e1ffff... (7 Replies)
Discussion started by: beca123456
7 Replies

9. Shell Programming and Scripting

Unable to match string within awk printf

Hi All I am working to process txt file into csv commo separated. Input.txt 1,2,asdf,34sdsd,120,haahha2 2,2,wewedf,45sdsd,130,haahha ..... .... Errorcode.txt 120 130 140 myawk.awk code: { BEGIN{ HEADER="f1,f2,f3,f4,f5,f6" (4 Replies)
Discussion started by: krsnadasa
4 Replies

10. Shell Programming and Scripting

Awk, if line after string does not match insert

I have a large file with interface records. I need to check every record that has the string "encapsulation bridge1483" and if the next line after this does not have "ip description" then I need to insert a line to add "ip description blah_blah_blah. Sample file: interface atm 1/0.190158... (3 Replies)
Discussion started by: numele
3 Replies
ndp(1M) 																   ndp(1M)

NAME
ndp - IPv6 Neighbor Discovery cache display and control SYNOPSIS
host interface] interface] interval interface] host interface] interface] interface] interface host hw_addr filename DESCRIPTION
The command displays and modifies the IPv6 Neighbor Discovery cache as specified in the IPv6 Neighbor Discovery (ND) protocol. Options recognizes the following options and arguments: host Display the current Neighbor Discovery cache entries for the host specified by host, which is either a name present in the hostname database (see hosts(4)), or an IPv6 address expressed in colon notation (see inet6(3N)). Select the Neighbor Discovery cache entries for the specified interface. There is no distinction between primary and secondary interfaces. Therefore, specifying is the same as speci- fying Display host addresses in IPv6 colon notation. If this option is not specified, attempts to display host addresses symbolically first, and falls back to displaying the host addresses in IPv6 colon notation if that failed. Display all Neighbor Discovery cache entries. Continuously display all Neighbor Discovery cache entries, updated at each interval, measured in seconds. Deletes Neighbor Discovery cache entries with IP addresses that are not associated with local interfaces for the host specified by host. Flushes all Neighbor Discovery cache entries with IP addresses that are not associated with local interfaces. These are entries with the (local) flag set. Refer to the section of this manpage for information about flags. (Quiet) Do not write anything to standard output. This option only applies to and options. Display the prefix list in the Neighbor Discovery cache table. The prefix list defines a set of IP address ranges that the host can reach. The prefix flags are for on-link, and for au- tonomous. The on-link flag indicates that addresses with that prefix can be reached directly without going through a router. The autonomous flag indicates that the prefix came from stateless autoconfiguration. Flushes all autoconfigured addresses learned from prefixes advertised by the Router Advertisement Messages. Create a Neighbor Discovery cache entry for the interface specified by interface, the host specified by host, and the hardware address (link-layer address) specified by hw_addr. The hw_addr is specified as where each x is a hexadecimal digit. If is specified, the entry is published, which means that this system will respond to Neighbor Solicitation for the speci- fied "host" even though the host address is not its own. If is specified, it means that the published entry refers to an anycast address. This parameter can only be specified when the parameter is specified. Create Neighbor Discovery cache entries from the specifications found in the file specified by filename. Each entry in this file specifies the interface, host, hw_addr, and optionally the flag. For example, the content of this file can be: The use of and options requires root privileges. Contents A Neighbor Discovery cache entry includes the following fields: o host (neighbor's host name or IP address) o hardware address (link layer address) of host o interface name o state o flags The state of an entry can be or o An entry is in an state if address resolution is in progress and the hardware address of the neighbor has not been determined. o An entry is in a state if the neighbor is known to have been reachable recently. o An entry is in a state if the neighbor is no longer known to be reachable. However, no attempt has been made to verify its reachability because no traffic has been sent to this neighbor. o An entry is in a state if the neighbor is no longer known to be reachable, and traffic has recently been sent to the neighbor. o An entry is in a state if the neighbor is no longer known to be reachable, and unicast Neighbor Solicitation probes have been sent to verify reachability. The flags can be (Deprecated), (Local), (Published), (Temporary), (Auto), or (anycast). A deprecated address can be used for receiving packets, but it should not be used for sending packets because its validity is expected to expire soon. The local flag indicates that this Neighbor Discovery cache entry corresponds to an interface on this host. The published flag indicates that the host will respond to Neigh- bor Solicitations on this IPv6 address. The temporary flag indicates that the address has a randomly generated interface identifier which changes over time. The autonomous flag indicates that the prefix for the address came from stateless address autoconfiguration. The any- cast flag indicates that the address is an anycast address. DIAGNOSTICS
returns a non-zero value to indicate errors. A zero return value indicates success. EXAMPLES
The following output shows the local interfaces and the IP addresses assigned to them. Name Mtu Address/Prefix Ipkts Opkts lan1 1500 fe80::210:83ff:fef7:3a21/10 982 759 lan1:1 1500 fec0::9:210:83ff:fef7:3a21/64 0 0 lan3 1500 fe80::210:83ff:fef7:7a9d/10 0 0 lo0 4136 ::1/128 57 57 To display the entire Neighbor Discovery cache: Destination Physical Address Interface State Flags fe80::202:fdff:fe36:8720 0:2:fd:36:87:20 lan1 STALE - fec0::9:210:83ff:fef7:3a21 0:10:83:f7:3a:21 lan1:1 REACHABLE LP fe80::210:83ff:fef7:3a21 0:10:83:f7:3a:21 lan1 REACHABLE LP fe80::210:83ff:fef7:7a9d 0:10:83:f7:7a:9d lan3 REACHABLE LP To show Neighbor Discovery cache entries for a host: Destination Physical Address Interface State Flags fe80::210:83ff:fef7:3a21 0:10:83:f7:3a:21 lan1 REACHABLE LP To show Neighbor Discovery cache entries for an interface: Destination Physical Address Interface State Flags fe80::210:83ff:fef7:7a9d 0:10:83:f7:7a:9d lan3 REACHABLE LP To delete a Neighbor Discovery cache entries for a host and an interface: fe80::202:fdff:fe36:8720 (fe80::202:fdff:fe36:8720) deleted. To show the prefix list: Prefix List Interface Valid Preferred Flags Entries Lifetime Lifetime fec0:0:0:9::/64 lan1 167 107 A fe80::/10 lan1 inf inf LA fe80::/10 lan3 inf inf LA To add an entry in the Neighbor Discovery cache: nodeb (2001::1) added. Destination Physical Address Interface State Flags fe80::210:83ff:fef7:7a9d 0:10:83:f7:7a:9d lan3 REACHABLE LP 2001::1 0:1:2:3:4:5 lan3 - - To flush all remote entries: nodea (fe80::202:fdff:fe36:8720) flushed. nodeb (2001::1) flushed. AUTHOR
was developed by HP. SEE ALSO
hosts(4), inet6(3N), ndp(7P). Neighbor Discovery for IP Version 6 (IPv6), RFC2461, Narten, Nordmark, Simpson. IPv6 Stateless Address Autoconfiguration, RFC2462, Thomson, Narten. ndp(1M)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy