delete last line in all the file in a directry

Hi Friends,

Following script will replace "prd123" to "tst123" for all the .csh file the directry.

for i in *.csh
echo '$i'
do
ex - ${i} <<EOF
%s/prd123/tst123/g
wq!
EOF
done

Like this can I make a script which will delete the last line of all .csh file
in the directry.

Thanks in advnce !!!!

yes you can - '$d'
P.S. Pls use vB Codes when quoting code like so:

```text
my code goes here
```

I am not sure about ex but it basically has the same syntax as sed and I think this command line is quite as clear (since vgersh99 pointed out the $d). If You can use sed instead.

This will remove the last line of all *.csh files in You current working directory. The -i options means edit in place, which means to replace the original.
Use the command line

if You want to keep the original with a bak extension.

/Lakris

PS
Btw, is this a test or assignment or something? :wink:

I love solving problems with one line of code:

perl -nli -e 'print unless eof' *.csh

And no loops!

The "sed" solution will work also if the "-i" flag is supported.

But sed is shorter! :wink:

Thanks Friends for your help.

Thanks a lot gus2000,

Yours coding working finely!!

Lakris ,
I tried your code in command prompt. but it thorws some errors.
$ sed -i -e '$d' *.csh
sed: illegal option -- i
$

-i option of sed - in place editing is available only with GNU sed

how to remove extra spaces or new line character from a file using unix commands?

this should logically be a new thread

however to remove extra spaces

sed 's/  *//g' filename

to remove empty lines

sed -i '/^$/d' filename

shorter as in:
(a) has less number of characters on the command line
or
(b) takes less time to execute (is more efficient)
?