Computer Science, asked by basantkumar2964, 1 year ago

Write a program to read all txt files (that is files that ends with .text) in the current directory and merge them all to one txt file and returns a file descriptor for the new file.

Answers

Answered by ashwani381
0
This is technically what cat("concatenate") is supposed to do, even though most people just use it for outputting files to stdout. If you give it multiple filenames it will output them all sequentially, and then you can redirect that into a new file; in the case of all files just use * (or /path/to/directory/* if you're not in the directory already) and your shell will expand it to all the filenames

find /path/to/directory/ -name *.csv -print0 | xargs -0 -I file cat file > merged.file

Very useful when your files are already ordered and you want to merge them to analyze them.

More portably:

find /path/to/directory/ -name *.csv -exec cat {} + > merged.file

HOPE this answer is helpful for u

Similar questions