Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all
I concatenate files using cat. Each file contains only one csv data. for example,
file1
100file2
200cat file1 file2 > newfile
newfile
100
200However, is there any way to insert identifier when using cat command?
for example,
newfile should have
file1 100
file2 200
Thanks in advance.
No, but this script solves the problem:
# no error checking
rm -f newfile
for i in file1 file2
do
printf "%s " $i >> newfile
cat "$i" >> newfile
done
Report Offensive Follow Up For Removal
Thanks a lot
However, I gotfile1100
file2200Is there any way to create CSV (comma delimited) or insert space?
Report Offensive Follow Up For Removal
I don't know what shell you are using (I'm using ksh), but this printf statement:
printf "%s " $i >> newfile
has a space after the %s format qualifer, and it works fine.
This example uses a pipe symbol instead of the space:
printf "%s|" $i >> newfile
Report Offensive Follow Up For Removal
![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |