最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

AWK copy value from $1 to line below - Stack Overflow

programmeradmin5浏览0评论

Input file.

44

55



14
15

16

I want to get an output file.

44
44
55
55
55
55
14
15
15
16
16 

I tried.

awk '{print $NF-1}' plik 
43
-1
54
-1
-1
-1
13
14
-1
15

Input file.

44

55



14
15

16

I want to get an output file.

44
44
55
55
55
55
14
15
15
16
16 

I tried.

awk '{print $NF-1}' plik 
43
-1
54
-1
-1
-1
13
14
-1
15
Share Improve this question edited yesterday Tedee12345 asked 2 days ago Tedee12345Tedee12345 1,3624 gold badges17 silver badges26 bronze badges 8
  • Why are there 2 "16" lines at the end of the output? Is that because you have a blank line at the end of the input or because you always want to re-print the last input line at the end of the output or something else? – Ed Morton Commented 2 days ago
  • $NF will return an empty string when there are 0 argument on a line. $NF-1 will, because of this, return -1. – Luuk Commented 2 days ago
  • 1 What should the first line of output be if the first line of input is empty? – Ed Morton Commented 2 days ago
  • @EdMorton: "copy value from $1 to line below", not: "repeat value from previous line"
发布评论

评论列表(0)

  1. 暂无评论