I'm dealing with some text files containing lists of numbers. Each number is on a separate line. Some numbers have forward slashes included (like 11152/3), and some don't (like 11276), which is okay. However, there are also lines that contain just a mix of slashes and spaces with no actual numbers. Is there any way to use sed or awk to remove those unwanted slashes while keeping the valid numbers intact?
3 Answers
You might want to try using `grep '[0-9]'` to filter out any lines that don’t have any digits. It can effectively remove those unwanted lines with just slashes and spaces.
While `grep` is an option, since you’re looking specifically to use `awk` or `sed`, you can do something like `awk '/[0-9]/ {print}'` or for `sed` try `sed -n '/[0-9]/p'`. Both will help in keeping lines with actual numbers.
It’d be really helpful to see some examples of your data. Specifically, share lines that are correct (no slashes), those that are correct with slashes, and lastly, the lines that contain only slashes. This way, we can better understand the patterns you’re working with!
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String