2014-07-02 57 views
11

除去前两行我有一个文本文件的输出如下:庆典 - 如何从输出

106 pages in list 
.bookmarks 
20130516 - Daily Meeting Minutes 
20130517 - Daily Meeting Minutes 
20130520 - Daily Meeting Minutes 
20130521 - Daily Meeting Minutes 

我期待从我的输出删除第一个2行。我用来执行的这个特定的shell脚本总是拥有前两行。

我这是怎么产生和读取文件:

#Lists 
PGLIST="$STAGE/pglist.lst"; 
RUNSCRIPT="$STAGE/runPagesToMove.sh"; 

#Get List of pages 
$ATL_BASE/confluence.sh $CMD_PGLIST $CMD_SPACE "$1" > "$PGLIST"; 

# BUILD executeable script 
echo "#!/bin/bash" >> $RUNSCRIPT 2>&1 
IFS='' 
while read line 
    do 
    echo "$ATL_BASE/conflunce.sh $CMD_MVPAGE $CMD_SPACE "$1" --title \"$line\" --newSpace \"$2\" --parent \"$3\"" >> $RUNSCRIPT 2>&1 
done < $PGLIST 

如何删除那些最上面两行?

+0

这些行看起来像是在其他脚本中生成的。尝试在其他文件中查找'echo'语句,例如'runPagesToMove.sh'和'confluence.sh'。如果你发布这些文件,有人可能能够解决这个问题,但这个问题并不能从给出的代码中解决。 – Adam

回答

14

经典的答案会用sed删除线1和2:

sed 1,2d "$PGLIST" 
+0

昨晚我有这个工作 - './runscript.sh>“$ PGLIST”| sed 1,2d $ PGLIST'但由于某种原因,它现在不工作。所以,我也尝试过这种方式,但没有运气。 './runscript.sh>“$ PGLIST”| sed 1,2d $ PGLIST> $ PGLIST;' – noober

+0

昨晚你没有显示'正在工作'。昨天晚上,你要么省略了'>',要么你用分号(或换行符)代替'|'。警惕尝试读取和写入管道中的单个文件;通常在读取文件之前最终会破坏文件,这会导致恼怒。总的来说,我认为你要找的是'./runscript.sh | sed 1,2d>“$ PGLIST”',但我无法确定。 –

14

您可以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 
+0

哇,甚至可以在macOS上运行! macOs在其“man”页面中没有提到这一点。 – Patrick

5

AWK方式:

awk 'NR>2' "$PGLIST"