View Single Post
  #2 (permalink)  
Old 08-16-2008, 03:46 AM
nixcraft's Avatar
nixcraft nixcraft is offline
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,680
Thanks: 11
Thanked 241 Times in 181 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
i want to sed the whole line to be sorted time alone in new line and date alone in another new line.
which means the new result should be like this:-

Thu Aug 14
13:07:26
No need to use sed, just use:
Code:
date +"%a %b %d"
date +"%T"
%a, %b and others known as FORMAT controls. They control the output of date. To see all interpreted sequences, read man page:
Code:
man date
Quote:
i got this command which shows my ip address
who am i | sed 's/[^(]*(\([^)]*\))/\1/'
the problem thats sed command shows also character between the numbers which means it does not show the ip ,, but it shows the whole hostname.
To see your own IP address use ifconfig command:
Code:
/sbin/ifconfig 
/sbin/ifconfig eth0
/sbin/ifconfig eth0 | grep inet
Now same stuff using awk:
Code:
ifconfig eth0| awk 'NR==2 {print $2}' | awk -F: '{print $2}'
See
Shell Script To Read IP Address ( Find Ip Address Script )

Quote:
for example if i type the command
who am i | sed 's/[^(]*(\([^)]*\))/\1/'
the result will be
sde-84-109-50-43.red.sde.net
now i need the numbers only
which means the new result should be
84.109.50.43 (with dot
Try to convert hostname to IP using host command
Code:
host $(who am i | sed 's/[^(]*(\([^)]*\))/\1/') | awk '{ print $4}'
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote