bash - 如何从输出中删除前 2 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24542425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash - how to remove first 2 lines from output
提问by noober
I have the following output in a text file:
我在文本文件中有以下输出:
106 pages in list
.bookmarks
20130516 - Daily Meeting Minutes
20130517 - Daily Meeting Minutes
20130520 - Daily Meeting Minutes
20130521 - Daily Meeting Minutes
I'm looking to remove the first 2 lines from my output. This particular shell script that I use to execute, always has those first 2 lines.
我希望从我的输出中删除前 2 行。我用来执行的这个特定的 shell 脚本总是有前两行。
This is how I generated and read the file:
这是我生成和读取文件的方式:
#Lists
PGLIST="$STAGE/pglist.lst";
RUNSCRIPT="$STAGE/runPagesToMove.sh";
#Get List of pages
$ATL_BASE/confluence.sh $CMD_PGLIST $CMD_SPACE "" > "$PGLIST";
# BUILD executeable script
echo "#!/bin/bash" >> $RUNSCRIPT 2>&1
IFS=''
while read line
do
echo "$ATL_BASE/conflunce.sh $CMD_MVPAGE $CMD_SPACE "" --title \"$line\" --newSpace \"\" --parent \"\"" >> $RUNSCRIPT 2>&1
done < $PGLIST
How do I remove those top 2 lines?
如何删除前两行?
回答by Gergo Erdosi
You can achieve this with tail
:
您可以通过以下方式实现tail
:
tail -n +3 "$PGLIST"
-n, --lines=K output the last K lines, instead of the last 10; or use -n +K to output starting with the Kth
-n, --lines=K output the last K lines, instead of the last 10; or use -n +K to output starting with the Kth
回答by Jonathan Leffler
The classic answer would use sed
to delete lines 1 and 2:
经典答案将用于sed
删除第 1 行和第 2 行:
sed 1,2d "$PGLIST"
回答by Kent
awk way:
awk 方式:
awk 'NR>2' "$PGLIST"