KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am learning awk/gawk. So recently I just try to solve any problem with it to gain more practice opportunities. My coworker asked a question yesterday, "how to remove first and last line from file" . I know that sed '1d;$d' file would work. also head/tail works too even if the poor performance. I told him the sed one, he was happy. Later, I was trying to wrote an awk one-liner: so far what I got is: awk 'NR>1{a[++k]=$0}END{for(i=1;i<k;i++)print a[i]}' This will store whole file in array just to skip the last line. I feel that there should be an easier(or better) way to do that.. (if there is no easier or faster or better way, I would remove the question)
Tags (comma-separated)
Save Edits
Cancel