PDA

View Full Version : [ubuntu] how can i delete text via the command line



z3nhakr
July 10th, 2012, 04:00 AM
i use "iwlist wlan0 scan" to scan for wifi then i use "grep essid" to get the line with the essid which is " ESSID:"NETGEAR"". how can i delete the spaces and "ESSID:" so i only have "NETGEAR" left? is there a way with grep?

glennric
July 10th, 2012, 04:04 AM
You can pipe the output to sed, awk, or cut and manipulate the text using those utilities. For example

iwlist wlan0 scan | grep ESSID | sed 's/ESSID: //'
You may need to adjust that a bit for the precise format the text is returned from iwlist in.

steeldriver
July 10th, 2012, 01:33 PM
although personally I'm more comfortable with sed, I think awk would be a more natural choice in this case - something like:


iwlist wlan0 scan | awk 'BEGIN {FS=":"}{if ($1 ~ /[ \t]*ESSID/) print $2;}'

asmoore82
July 10th, 2012, 01:46 PM
Just to mix things up: cut !


iwlist wlan0 scan | grep ESSID | cut -d\" -f2


is there a way with grep?
:P

iwlist wlan0 scan | grep ESSID | grep -oE '"[^"]+"' | grep -oE '[^"]+'

SlugSlug
July 10th, 2012, 02:42 PM
Just to mix things up: cut !


iwlist wlan0 scan | grep ESSID | cut -d\" -f2
:P

iwlist wlan0 scan | grep ESSID | grep -oE '"[^"]+"' | grep -oE '[^"]+'


I love this forum :popcorn: