shell


cat files together with newline in shellscript


I am cating files together recursively in a directory, however, some files are missing a newline after the last line, so this creates a problem. How do I append a newline to each file in the process? here's the shellscript
find $1 -type f |xargs cat > test.csv
I realize this is a fairly old question, but I had the same problem. None of the answers above seemed to work with files with whitespace in them, because of the usage of backticks and /usr/bin/find. Doing so would require me to change $IFS which is absolutely not necessary unless you only need to use files.
This is my take on it:
for i in *; do cat "$i" && echo ""; done
You can use a loop:
find $1 -type f | while IFS= read -r file
do
cat "$file"
echo
done > test.csv
Use a for-loop:
for file in $(find .); do cat $file >> huge_file; echo " " >> huge_file; done
find $1 -type f |xargs awk 'FNR==1 && NR>1 {print ""} {print}'
or
find $1 -type f |xargs awk 'ENDFILE {print ""} {print}'
If you wanted to add a newline for any file that does not have a newline on its own as the last line, you can do the following:
for f in `find $1 -type f`; do sed -E '$s/(.*\S+.*)/\1\n/' $f; done
EDIT: My first answer used xargs, but that didn't provide the expected result, so fell back on a loop.

Related Links

Unexpected empty result from shell script that calls awk
Input a command result in a command line program
How can I execute a script that runs within an xterm/xgterm?
ssh executing nsenter as remote command with interactive shell in golang to debug docker container
ksh88 changing single quotes to double quotes inside heredocs?
Shell script replace variable with another variable have content & character by using sed
shell script that send email before exiting
how can we remove last 7 lines of file in unix [duplicate]
Shell Script improvement for getting diff result
hbase shell command - scan and Filter
How can I conditionalize a WiX custom action based on user priviledges
What does 1>&2 mean in shell? [duplicate]
UNIX: recursively paste a substring into the same string in unix
docker login in shell script dont work
Run a script every x seconds without waiting for it to complete
rename files in current folder (mandatory : for mv cut commands)

Categories

HOME
gdb
angular2-material
3d
themes
hessian
carousel
rom
nuget-package
frontend
pcl-crypto
dkim
heap
mod-security
alamofire
filechannel
nancy
comsol
eip
selectize.js
cfml
visual-glitch
spring-async
dpdk
aggregation
jquery-callback
surveymonkey
interbase
jackson-modules
android-maps
linked-data
bioinformatics
gp
google-cast
event-flow
powershell-ise
git-squash
login-script
processwire
reason
xcode7.3
amazon-ses
filesystemwatcher
demo
comparison-operators
xv6
laravel-elixir
levenshtein-distance
movilizer
strftime
facebook-pixel
geotiff
azure-cli
quicktime
lsyncd
cvxpy
flex4.6
refinerycms
assertion
jdi
coda
finalbuilder
ocra
graphics2d
diff3
public-html
structuremap3
rickshaw
personalization
codeplex
tinyxml
eclipse-kepler
ebay-lms
hidapi
scmmanager
css-reset
swfobject
web-farm
iboutlet
garbage
mapping-by-code
oracle-enterprise-linux
floating-point-exceptions
htdocs
umra
uipagecontrol
cac
zen
contentpresenter

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App