Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

removing the first and last lines of a flat file in unix

Hi,

 How do I remove the firsta nd last lines of a flat file in unix korn shell?
0
LuckyLucks
Asked:
LuckyLucks
2 Solutions
 
ozoCommented:
mv file file.$$
sed -n -e x -e '3,$p' file.$$ > file
0
 
omarfaridCommented:
len=`wc -l filename`
len=`expr $len - 1`
head -n $len $filename > newfile
len=`expr $len - 1`
tail -n $len newfile > newfile2
0
 
AkiraIrisCommented:
By line number (1d deletes first line, $d deletes last line):

sed -i'' -e '1d' -e '$d' filename
0
 
LuckyLucksAuthor Commented:
Is that " (opening double quoute) after -i? I tried sed -i -e '1d' -e '$d' myfile and I got roor - illegal option -i
0
 
ozoCommented:
That's '' not "
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now