Operating System - Linux
1755717 Members
3756 Online
108837 Solutions
New Discussion юеВ

use of VI editor in script

 
SOLVED
Go to solution
Muthukumar_5
Honored Contributor

Re: use of VI editor in script

I feel JRF is shown the best. :)

#!/bin/sh
oldfile=abc
newfile=$(head -1 ${oldfile})
perl -ne 'print if ($. != 1)' ${oldfile} > ${newfile}
rm -f ${oldfile}

# END
exit 0

--
Muthu
Easy to suggest when don't know about the problem!
Hein van den Heuvel
Honored Contributor

Re: use of VI editor in script



Simple awk solution:

awk 'END{system("rm -i " ARGV[1])} {if (NR==1) {f=$1} else {print >> f}}' x


- at end (ask to) delete the file
- if line 1 then pickup filenam in f
- any other line, print to file f

Hein.

yogesh_4
Regular Advisor

Re: use of VI editor in script

Hi All,
Thanks for all help. I have used user solution and it resolved my problem.
Many thanks for your help.