Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing charaters

Status
Not open for further replies.

zypher74

Technical User
Apr 10, 2005
4
US
im trying to use the GET command on to find my public address then pipe it to awk to show only the address can anyone tell me the command(s) to remove the last 14 charaters from field 6

Thanks
 
I'm not familiar with GET, but this gets the last 14 characters of field 6. Using nawk for solaris:

Code:
#!/bin/ksh

gline="1 2 3 4 5 Xab12345678901234 seven eight"

estr=$(echo "$gline"|nawk ' {  print substr($6, (length($6)-13)) } ')
echo "$estr"
 
Hi:

I may have misinterpreted what you asked for. If you want to remove the last 14 characters of field 6 and save everything else:

Code:
#!/bin/ksh

gline="1 2 3 4 5 Xab12345678901234 seven eight"

echo "$gline"|nawk ' {  gsub(/..............$/, "", $6); print $0 } '
 
thank you very much the 1st code sample is what i needed
will try to be clearer next time
 
well it do not work
Current IP Check</title></head><body>Current IP Address: 199.39.243.44</body></html>

how can i get just the ip address
 
hate to keep replying to my own thread but
here is what i came up with
GET | awk ' { gsub(/...............$/, "", $6); print $6 } '

any better way ??
 
You may try this:
GET | awk '{print substr($6,1,index($6,"<")-1)}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Why don't you do it all from within (g)awk?

BEGIN {
i=0
while ( (ARGV[1] | getline) > 0) {
if ($0 /regexp/) {array[i++] = $0}
}
}
 
GET is part of the HTTP protocol. It should return where it is pointed. If it is pointed to a file it should return the file. If it points to a CGI script, it should execute the script and return the output.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top