racbern
1
Hello All,
I am new to using sed, and I need to extract from the string data after : delimeter.
Can you help me please with the sed command?
Here's the input:
ipAddress: 10.20.10.11
ioIpAddressNodeB: 10.20.10.10
ioIpAddressNodeA: 10.20.10.9
ipAddress: 0.0.0.0
Expected Output:
10.20.10.11
10.20.10.10
10.20.10.9
0.0.0.0
Thanks in advance to anyone who'll reply.
Regards,
racbern
Here is one way of doing what you want using sed.
sed -n 's/^.*: \(.*$\)/\1/p' yourfile
BTW, awk is probably a simpler tool to use for this type of task.
awk '{ print $2 }' yourfile
you forgot the FS definition:
awk -F: '{ print $2 }' yourfile
Actually no. The -F: option is not required because of the space after the colon on each line.
shell
#!/bin/sh
while IFS=: read one two
do
echo $two
done < file
output:
# ./test.sh
10.20.10.11
10.20.10.10
10.20.10.9
0.0.0.0
awk -F: '{print $2}' file