Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > remove string from field "beta:23.52"
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 16th September 06:52
otako
External User
 
Posts: 1
Default remove string from field "beta:23.52"



Hello,
with the following on the bash command line-

echo "alpha, beta:23.52, 21.46" | awk -F, '{print $2}'

the output is-

beta:23.52

can awk remove the "beta:" string so that only the "23:52" is
output using an option and without relying on 'sed' or 'cut' to
filter the input to awk.
ie
echo "alpha, beta:23.52, 21.46" | awk -F, '{print $2}'| cut -d ":" -f 2

23.52

I have used OFS in a script with some success but would like to
know if it is possible to do this on the command line.


thanks,
keith.
  Reply With Quote


 


2 16th September 06:52
grant
External User
 
Posts: 1
Default remove string from field "beta:23.52"



grant@peetoo:~$ echo "alpha, beta:23.52, 21.46" | awk -F, '{print $2}'| cut -d ":" -f 2
23.52
grant@peetoo:~$ echo "alpha, beta:23.52, 21.46" | awk -F, '{split($2,k,":");print k[2]}'
23.52

Grant.
--
.... The computer scientist, who had listened to all of this said,
"Yes, but where do you think the chaos came from?"
  Reply With Quote
3 16th September 06:52
chris f.a. johnson
External User
 
Posts: 1
Default remove string from field "beta:23.52"


echo "alpha, beta:23.52, 21.46" | awk -F'[,:]' '{print $3}'


Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Reply With Quote
4 16th September 06:52
otako
External User
 
Posts: 1
Default remove string from field "beta:23.52"


thanks Chris and Grant

ok now and understand the syntax of -F[] and split.

---
keith.
  Reply With Quote
Reply


Thread Tools
Display Modes




666