Remove last line from all files of a specific extension

flappingwings

I have several files with same extension .txt in a directory. I want to remove the last line from all .txt files.

What I did is

find . -type f -name '*.txt' -exec sed '$d' {} \;

This prints the desired output from sed to the terminal for every .txt file.

What I want is to modify the respective files.

Ravi Saroch

Try this:--

sed  -i '$d' *.txt

"$" is used as a line number and means the last line in the file.

"d" is usd to delete the respective line(last line in this case).

"*.txt" is used to select all files whose extension is .txt in the present directory.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Remove a specific extension from all the files in a directory

How to remove the last line of all files from a directory?

How to remove all files with specific extension in folder?

How to find a specific file recursively and delete the last line from all files found in linux?

Recursively execute all files with a specific extension via command line

Remove a specific suffix from all the files in a directory

Remove the last extension from path

Remove and ignore all files that have an extension from a git repository

Remove all files of a type (file extension) from whole directory tree

sed-remove all but last occurrence of a character from a line

Get all files with a specific extension

show specific lines from all files with .txt extension

show a group of specific lines from all files with .txt extension

Copy all files with specific extension from remote server with Java

Remove specific (complex) line from MANY files (sed?)

Remove last line from a jTextPane

Git remove specific files from all previous commits

Script to remove diagnostic files with specific extension

remove character on the last line that specific word appears

remove character on the last line that specific word appears

How to creat a symbolic link to all files with a specific extension from a specific directory using a shell script?

How to remove union all in last line of output

Find all files that are NOT of a specific type/extension in folder?

Loop through all the files with a specific extension

Find all files by extension excluding specific directories

How to get a list of all files with a specific extension?

how to remove all files exclude specific files

Remove all hidden files except specific files

Remove first 3 characters and last 1 character from all mp3 files in all subdirectory