Lets consider i have a image.jpg and a csv file ,how can i pre append the actual image.jpg into csv file
Example CSV file
Name,Age,Country AAA,24,JJJ BBB,25,KKK
My expectation is to pre append the image.jpg as it is into csv file
Expectec output
`image.jpg
`Name,Age,Country
AAA,24,JJJ
BBB,25,KKK“
I have tried, below code but its giving the csv file in non readable format,
<code>#!/bin/bash
image_file="image.jpb"
source_csv="Customer.csv"
temp_csv=$(mktemp)
# Check if the image file exists
if [ ! -f "$image_file" ]; then
echo "Image file not found!"
exit 1
fi
# Check if the source CSV file exists
if [ ! -f "$source_csv" ]; then
echo "Source CSV file not found!"
exit 1
fi
# Create a temporary file with image data prepended
{
echo "-----BEGIN IMAGE FILE-----"
cat "$image_file"
echo "-----END IMAGE FILE-----"
echo
cat "$source_csv"
} > "$temp_csv"
# Replace the target CSV with the temporary file content
mv "$temp_csv" "$source_csv"
</code>
<code>#!/bin/bash
image_file="image.jpb"
source_csv="Customer.csv"
temp_csv=$(mktemp)
# Check if the image file exists
if [ ! -f "$image_file" ]; then
echo "Image file not found!"
exit 1
fi
# Check if the source CSV file exists
if [ ! -f "$source_csv" ]; then
echo "Source CSV file not found!"
exit 1
fi
# Create a temporary file with image data prepended
{
echo "-----BEGIN IMAGE FILE-----"
cat "$image_file"
echo "-----END IMAGE FILE-----"
echo
cat "$source_csv"
} > "$temp_csv"
# Replace the target CSV with the temporary file content
mv "$temp_csv" "$source_csv"
</code>
#!/bin/bash
image_file="image.jpb"
source_csv="Customer.csv"
temp_csv=$(mktemp)
# Check if the image file exists
if [ ! -f "$image_file" ]; then
echo "Image file not found!"
exit 1
fi
# Check if the source CSV file exists
if [ ! -f "$source_csv" ]; then
echo "Source CSV file not found!"
exit 1
fi
# Create a temporary file with image data prepended
{
echo "-----BEGIN IMAGE FILE-----"
cat "$image_file"
echo "-----END IMAGE FILE-----"
echo
cat "$source_csv"
} > "$temp_csv"
# Replace the target CSV with the temporary file content
mv "$temp_csv" "$source_csv"
I want the image file to be pre appended as it is into the csv file and in readable format