![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to read the configuration file from shell script | nishanth hampal | Shell Programming and Scripting | 7 | 02-27-2008 03:42 AM |
| Read variable from file in a C shell script | haouesse | Shell Programming and Scripting | 2 | 11-07-2006 09:34 AM |
| read or search the item in a file sequentially by position using unix shell script? | lok | UNIX for Dummies Questions & Answers | 6 | 07-12-2006 06:53 AM |
| Shell Script to read specific lines in a file | varshanswamy | Shell Programming and Scripting | 5 | 08-22-2005 07:12 PM |
| Korn Shell Script - Read File & Search On Values | run_unx_novice | Shell Programming and Scripting | 2 | 06-15-2005 07:20 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Shell script to read file into variable
the script i am trying to write will allow my server to give itself an ip address.
So far i am up to the following but i'm stuck. tracert -m 1 > traceroute.txt [Outputs] 1 routername (ipaddr) 2.094 ms 1.789 ms 1.243 ms i want to get ipaddr as a variable and use it to write the ifcfg-eth script. How should i go about this? |
|
||||
|
Code:
# one way that does not use an intermediate file
tracert -m 1 | read one two ipaddr dummy
# from the file
awk '{ print $3}' traceroute.txt | read ipaddr
# if you want to lose the ( ) around the ipaddr if you really have one
awk '{ print $3}' traceroute.txt | tr -d '(' | tr -d ')' | read ipaddr
|
|
||||
|
i am using this in the script
traceroute -m1 ipaddr |grep 10.12 |awk '{ print $3}'| tr -d '(' | tr -d ')' | read ipaddr echo $ipaddr the only problem now is that it wont run as a single command. ipaddr=$ ( traceroute -m1 10.0.100.1 |grep 10.12 |awk '{ print $3}'| tr -d '(' | tr -d ')' ) tracert.sh: line 3: syntax error near unexpected token `|' tracert.sh: line 3: `ipaddr=( traceroute -m 1 10.100.0.100 |grep 10.12 |awk '{print $3}'| tr -d '(' | tr -d ')' )' |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, linux, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|