DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 18th November 2008
bigb89 bigb89 is offline
Fdisk Soldier
 
Join Date: May 2008
Posts: 69
Default How to remove a word and everything after?

Hi guys,

Here's what I'm trying to do. Let's say I have the following line:

43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0

How could I remove the word Bcast and anything after that word so that the line would look like this:

43.96.199.87

Please let me know of way that I can achieve this.

P.S. I really appreciate the help you guys have given me.
Reply With Quote
  #2   (View Single Post)  
Old 18th November 2008
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

Code:
# echo "43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0" | awk '{print $1}'
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #3   (View Single Post)  
Old 18th November 2008
anemos's Avatar
anemos anemos is offline
Fdisk Soldier
 
Join Date: May 2008
Location: Ελλάδα
Posts: 53
Default

Code:
echo 43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0 | sed s/"Bcast.*"/""/
Reply With Quote
  #4   (View Single Post)  
Old 18th November 2008
bigb89 bigb89 is offline
Fdisk Soldier
 
Join Date: May 2008
Posts: 69
Default

Thank you very much guys!

I was able to do exactly what I needed your help!
Reply With Quote
  #5   (View Single Post)  
Old 18th November 2008
drl's Avatar
drl drl is offline
Port Guard
 
Join Date: May 2008
Posts: 19
Default

Hi.

The other side of the coin is to extract a portion of a line. In this case we notice the string is field number 1. We can use another standard command similar to the awk solution:
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate extraction of field.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) cut
set -o nounset

echo
s="43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0"
echo " Input string: $s"
echo
echo " Results:"
echo "$s" | cut -d" " -f1

exit 0
Producing:
Code:
$ ./s1

(Versions displayed with local utility "version")
FreeBSD 4.11-STABLE
GNU bash 3.1.17
cut - no version provided for /usr/bin/cut.

 Input string: 43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0

 Results:
43.96.199.87
cheers, drl
Reply With Quote
  #6   (View Single Post)  
Old 28th August 2014
Mike-Sanders Mike-Sanders is offline
Fdisk Soldier
 
Join Date: Dec 2012
Posts: 52
Default

Another example below as well

Code:
echo 43.96.199.87 Bcast:43.96.199.255 Mask:255.255.255.0 | cut -w -f 1
__________________
www.tacoshack.xyz
Reply With Quote
  #7   (View Single Post)  
Old 30th August 2014
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

While useful, -w is a FreeBSD-specific extension to cut.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #8   (View Single Post)  
Old 31st August 2014
Mike-Sanders Mike-Sanders is offline
Fdisk Soldier
 
Join Date: Dec 2012
Posts: 52
Default

Was not aware that '-w' was limited to FreeBSD... appreciate the info.
__________________
www.tacoshack.xyz
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove Gnome and X Malakim Solaris 2 12th April 2009 12:10 PM
NIC with internal cable; how to remove? TerryP Off-Topic 9 14th July 2008 06:33 AM
Alternative Word Processing and Spreadsheet Applications enpey FreeBSD Ports and Packages 13 7th June 2008 09:27 AM
Remove/disable a former system user anomie Guides 6 19th May 2008 12:37 AM
remove kde and kde dependent apps ccc FreeBSD Installation and Upgrading 2 12th May 2008 02:11 PM


All times are GMT. The time now is 03:12 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick