我需要帮助输入一个sed命令来搜索下面 2000 年至 2009 年(含)之间发布的游戏。我尝试过 (/) 搜索,但它对我不起作用。
1 Wii Sports Wii 2006 Nintendo 41.36\n2 Super Mario Bros. NES 1985 Nintendo 29.08\n3 Duck Hunt NES 1985 Nintendo 26.93\n4 Tetris GB 1989 Nintendo 23.20\n5 Mario Kart Wii Wii 2008 Nintendo 15.91\n6 Wii Sports Resort Wii 2009 Nintendo 15.61\n7 Kinect Adventures! X360 2010 MS Game Studios 15.09\n8 New Super Mario Bros. Wii Wii 2009 Nintendo 14.53\n9 Wii Play Wii 2007 Nintendo 13.96\n10 Super Mario World SNES 1991 Nintendo 12.78\n11 New Super Mario Bros. DS 2006 Nintendo 11.28\n12 Pok\xc3\xa9mon Red/Green/Blue GB 1998 Nintendo 11.27\n13 Super Mario Land GB 1989 Nintendo 10.83\n14 Call of Duty: Black Ops X360 2010 Activision 9.76\n15 Mario Kart DS DS 2005 Nintendo 9.71\n16 Super Mario Bros. 3 NES 1990 Nintendo 9.54\n17 Grand Theft Auto:San Andreas PS2 2004 Rockstar Games 9.43\n18 Call of Duty: Modern Warfare X360 2011 Activision 9.07\n19 Grand Theft Auto V X360 2013 Rockstar Games 9.06\nRun Code Online (Sandbox Code Playgroud)\n
对于此用例,最好使用awk作为文本处理工具,同时您可以使用上面的内容来搜索您要查找的内容(请注意,这仅适用于您的列表):
sed -n '/200[0-9]/p' file
Run Code Online (Sandbox Code Playgroud)
-n :将抑制完整的文件输出
p命令:用于打印匹配的模式
使用AWK(假设列由制表符分隔):
awk -F '\t' '{if($4 >= 2000 && $4 <= 2009 ) {print $0}}' file
Run Code Online (Sandbox Code Playgroud)