2013-02-06 25 views
1

我是shell腳本編程的新手。我想從日誌文件中一次讀取3行。我知道如何逐行執行。我嘗試了三次使用<進行閱讀,並從腳本中調用腳本本身,但它不起作用。任何幫助表示讚賞。如何在shell腳本中讀取3行代碼

回答

4

一種方式:

$ while read l1 
> do 
> read l2 
> read l3 
> echo line1 is $l1 
> done < file 
0

TCL腳本在一個時間從文件

#!/usr/bin/tclsh 
set prev_count -1 
set fp [open "input-file.txt" "r"] 
set num_lines [split [read $fp] \n] 
for {set i 2} {$i < [llength $num_lines]} { incr i 3} { 
    set line_3 [lrange $num_lines [incr prev_count] $i] 
    set prev_count $i 
    puts "$line_3\n\n" 
} 
  • 開放閱讀3行的文件,使用分割命令
  • 分割文件
  • 使用Lrange從列表中選擇行數