Sponsored Content
Top Forums Shell Programming and Scripting awk not escape my bash variable Post 302545780 by winggundamth on Tuesday 9th of August 2011 01:28:12 PM
Old 08-09-2011
awk not escape my bash variable

I tried to parse data from switch configuration files

Code:
vlan 1727 name SQ5506-15 by port
 tagged ethe 8/1 to 8/2 
 untagged ethe 1/13 
!
vlan 2105 name SQ5620-7007(BR2) by port
 tagged ethe 8/1 to 8/2 
 untagged ethe 1/17 
!
interface ethernet 1/13
 port-name SQ5506-15.nic0
 rate-limit input fixed 10000000
 sflow forwarding
!
interface ethernet 1/17
 port-name SQ5620-7007.nic0
 rate-limit input fixed 100000000
 sflow forwarding
!

At first I parse interface number by device name and switch path with this command

Code:
INTERFACE=`awk '/^vlan(.*)'"$DEVICE "'(.*)/,/^!/' "$SWITCH_PATH" | awk '/untagged/{print $3}'`

Then I tried to get rate limit from interface that I parse from above with this command

Code:
RATELIMIT=`awk '/^interface ethernet '"$INTERFACE"'\r(.*)/,/^!/' "$SWITCH_PATH" | awk '/rate-limit/{print $4}'`

But it is showing an error

Code:
awk: /^interface ethernet 1/13\r(.*)/,/^!/
awk:                          ^ backslash not last character on line

If $INTERFACE is single number like "74" it will work but if $INTERFACE has forward slash like "1/13" it will showing an error as above. I have tried with put direct interface number and found that I have to put backslash before forward slash in interface number like this

Code:
RATELIMIT=`awk '/^interface ethernet '"1\/13"'\r(.*)/,/^!/' "$SWITCH_PATH" | awk '/rate-limit/{print $4}'`

I also tried with awk -v too but no luck. It is showing no error but still can't get value what I want

Code:
RATELIMIT=`awk -v INTERFACE="$INTERFACE" '/^interface ethernet INTERFACE\r(.*)/,/^!/' "$SWITCH_PATH" | awk '/rate-limit/{print $4}'`

I tried with every possible changing quote and double quote but still no luck. Can someone help me this?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

saving awk value in a bash array variable

hi all i am trying to save an awk value into an array in bash: total=`awk '{sum+=$3} END {print sum}' "$count".txt"` ((count++)) the above statement is in a while loop.. $count is to keep track of file numbers (1.txt,2.txt,3.txt,etc.) i get the following error: ./lines1:... (1 Reply)
Discussion started by: npatwardhan
1 Replies

2. Shell Programming and Scripting

assign awk output to bash variable

greetings all, I am have a heck of a time trying to accomplish a very simple thing. I have an array of "shortname<spaces>id" created from a dscl output. I want to assign shortname=word1 and id=word2. I have tried shortname=$(${textArray} | awk '{print $1}') - and get 'awk : cannot open... (3 Replies)
Discussion started by: macnetdaemon
3 Replies

3. Shell Programming and Scripting

Creating variable using awk in bash

I would like to create a variable within my bash script using awk. I'm reading in a line from an external file, then outputting to a new file in a specific format. But, it doesnt quite work as I have expected and could use some help. (A pertinent excerpt of ) the bash code is: count=1 ... (4 Replies)
Discussion started by: snoitacilppa
4 Replies

4. Shell Programming and Scripting

bash curl escape & in url

I'm running a curl command in bash, but the & in the middle causes the second half of the line to run in the background, here's what I'm trying to do: lat="37.451" lon="-122.18" url="http://ws.geonames.org/findNearestAddress?lat=$lat&lng=$lon" curl -s "$url" I tried escaping the & with \&,... (4 Replies)
Discussion started by: unclecameron
4 Replies

5. Shell Programming and Scripting

populate a bash variable from an awk operation

Hi, I'm trying to populate bash script variable, data_size with the size of the largest file in my current directory data_size=$(ls -lS | grep -v "total" | head -1) | awk '{ print $5 }' I've tried adding an echo before the call to awk data_size=$(ls -l | grep -v "total" | head -1) |... (2 Replies)
Discussion started by: mark_s_g
2 Replies

6. Shell Programming and Scripting

How to store a escape character in a Variable.?

How to store escape character in the variable. Var=abc,def,ghi,jkl echo ${Var} | sed -e "s/,/|\\\\./g;s/^/\\\\./g" \.abc|\.def|\.ghi|\.hjk Var1=`echo ${Var} | sed -e "s/,/|\\\./g;s/^/\\\./g"` Actual: ------- echo $Var1 .abc|.def|.ghi|.jkl Expected: --------- echo $Var1... (4 Replies)
Discussion started by: deepakwins
4 Replies

7. Shell Programming and Scripting

Problem with awk instructions and bash variable

Hi everyone, I'm trying to write a small script to automatize row data treatment. However, I got some trouble with the awk command. I want to use awk to extract a define paragraph from a text file. The first and final lines are defined externally in two variables called debut and fin. I... (2 Replies)
Discussion started by: TeaTimeSF
2 Replies

8. UNIX for Beginners Questions & Answers

Escape bash-special character in a bash string

Hi, I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user... (5 Replies)
Discussion started by: arcoa05
5 Replies

9. Shell Programming and Scripting

Escape characters in a variable

Debian 9 64x - LXDE How can i disable escape sequences in a variable? #!/bin/bash #mainscript . "./links.bash" echo "$red_start This text should be red $color_end"#!/bin/bash #links.bash #colors red_start="\eOutput that i get: \e Output expected: This text should be... (5 Replies)
Discussion started by: int3g3r
5 Replies

10. Shell Programming and Scripting

Bash variable expansion in awk script

Hello, I need to split a file into two of different locations by re-direction in awk. cat infle aaa 1 3 bbb 2 4 aaa 3 3 bbb 4 4 aaa 5 3 bbb 6 4 cat /storage/tmp/group_a.gtf aaa 1 3 aaa 3 3 aaa 5 3 cat /storage/tmp/group_b.gtf bbb 2 4 bbb ... (2 Replies)
Discussion started by: yifangt
2 Replies
VCONFIG(8)						      System Manager's Manual							VCONFIG(8)

NAME
vconfig - VLAN (802.1q) configuration program. SYNOPSIS
vconfig [lots of long options] DESCRIPTION
The vconfig program allows you to create and remove vlan-devices on a vlan enabled kernel. Vlan-devices are virtual ethernet devices which represents the virtual lans on the physical lan. OPTIONS
add [interface-name] [vlan-id] Creates a vlan-device on [interface-name]. The resulting vlan-device will be called according to the nameing convention set. rem [vlan-device] Removes the named vlan-device. set_flag [vlan-device] 0 | 1 When 1, ethernet header reorders are turned on. Dumping the device will appear as a common ethernet device without vlans. When 0(default) however, ethernet headers are not reordered, which results in vlan tagged packets when dumping the device. Usually the default gives no problems, but some packet filtering programs might have problems with it. set_egress_map [vlan-device] [skb-priority] [vlan-qos] This flags that outbound packets with a particular skb-priority should be tagged with the particular vlan priority vlan-qos. The default vlan priority is 0. set_ingress_map [vlan-device] [skb-priority] [vlan-qos] This flags that inbound packets with the particular vlan priority vlan-qos should be queued with a particular skb-priority. The default skb-priority is 0. set_name_type VLAN_PLUS_VID | VLAN_PLUS_VID_NO_PAD | DEV_PLUS_VID | DEV_PLUS_VID_NO_PAD Sets the way vlan-device names are created. Use vconfig without arguments to see the different formats. NOTES VLAN will use Broadcom's NICE interface when the network device supports it. This is necessary, since usually the hardware of these devices already removes the vlan tag from the ethernet packet. The set_flag option on vlan-devices created on such a physical net- work device will be ignored. Dumping the network-device will show only untagged(non-vlan) traffic, and dumping the vlan-devices will only show traffic intended for that vlan, without the tags. FILES
/proc/net/vlan/config /proc/net/vlan/[vlan-device] SEE ALSO
ip(8), ifconfig(8) AUTHORS
This manual page was written by Ard van Breemen <ard@kwaak.net> The vlan patch is written by Ben Greear <greearb@candelatech.com> VCONFIG(8)
All times are GMT -4. The time now is 04:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy