You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Geany中忽略大小写查找并删除含指定内容的整行

Solution to Remove Case-Insensitive "Found Device" Lines from Logs

Got it, let's fix this for you! The issue with your initial attempt was twofold: you weren't accounting for case insensitivity properly, and you didn't specify that you wanted to delete the entire matching line. Here are three reliable ways to get this done using common Unix/Linux tools you probably already have installed:

1. Use grep (Simple Reverse Match)

grep is perfect for quick filtering. The -v flag reverses the match (outputs lines that don't match), and -i enables case insensitivity:

grep -v -i "found device" your_log_file.log
  • To save the cleaned output to a new file:
    grep -v -i "found device" your_log_file.log > cleaned_log.log
    
  • If you want to modify the original file directly (GNU grep only):
    grep -v -i "found device" your_log_file.log --in-place
    

2. Use sed (In-Place Editing)

sed is ideal for direct file modifications. The /I flag (GNU sed) makes the match case-insensitive, and d deletes the matching line entirely:

sed -i '/found device/I d' your_log_file.log
  • Note for macOS/BSD sed: You need to add an empty string to the -i flag to avoid creating a backup file, and use -E for extended regex support:
    sed -i '' -E '/found device/i d' your_log_file.log
    

3. Use awk (Flexible Text Processing)

awk gives you extra flexibility if you need to expand your logic later. The !/found device/i syntax means "keep lines that don't match the pattern (case-insensitive)":

awk '!/found device/i' your_log_file.log > cleaned_log.log

Example Test

If your input log looks like this:

may 09 00:11:53 USER audit[1225]: Found device /dasd/cxvxc/...
may 09 00:11:53 USER audit[1226]: more text here
may 09 00:11:53 USER audit[1225]: Found device /mnt/cxvxc/...
may 09 00:11:53 USER audit[1225]: FOUND DEVICE /mnt/cxvxc/...

Running any of the above commands will output only the non-matching line:

may 09 00:11:53 USER audit[1226]: more text here

Pro Tip

Always test the command without modifying the original file first (e.g., run the grep command without redirecting to a file) to confirm it's filtering correctly before making permanent changes.

内容的提问来源于stack exchange,提问作者Frank

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 16:32:28