Cut a file by keyword

i need to cut a file by keyword

i have this file and i need to cut tail by this
config wifi-iface 'default_radio0'

i tried sed but nothing works

sed '/wifi-iface/,$d' /root/configurater/soureconfig/wireless

sed -e 's/^.\{wifi-iface\}//' /root/configurater/soureconfig/wireless

It may be easiest to use one of the following:

  • a text editor (like vi or nano)
  • UCI commands
  • the LuCI web interface
  • scp to transfer it to your computer and a text editor there, then back via scp again.

Obviously, a linux commandline option using sed or similar is workable, but I'd recommend the above options.

while uci -q delete wireless.@wifi-iface[0]; do :; done
uci commit wireless



maybe not so elegant, but works

sed -n '/wifi-device/,/wifi-iface/p' /etc/config/wireless | sed '$d'

You want everything in a file before a certain line of text. It appears from your file path that you're trying to do some automagic configuration in a script? This should do the trick for what you've asked:

FILENAME="/root/configurater/soureconfig/wireless";head -n $(($(grep -n "config wifi-iface 'default_radio0'" $FILENAME | cut -d":" -f 1)-1)) $FILENAME

This will return all lines in $FILENAME before the line which contains config wifi-iface 'default_radio0'.

The one drawback is that if the seach text doesn't exist, it returns the entire file except for the last line.

1 Like

also works like this

sed '/wifi-iface/,$d' /root/configurater/soureconfig/wireless

i get it now i was expecting sed would cut the original file but the comand gives an output
Thank you anyway

1 Like

i have it all i use it all the time
but this time i need a script to make it all for my dumb APs

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.