Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I input data into a csv by 'echo'-ing some values into another csv.

I tried echo "" and in the next line echo "values" but i get intermittent empty lines..

I need empty line only at the start....

share|improve this question
8  
Please show small example code, input data and output data –  grebneke 12 hours ago
add comment

2 Answers

There are many ways of doing this. Since you have not explained your issue with any detail, I am assuming that you are doing something like this:

values=$(grep foo csv1.csv)
echo "$values" > csv2.csv

At any rate, you seem to be extracting some lines of one csv file and inserting them into another. To add an empty line to the beginning of the new csv file, you do any of these:

echo  > csv2.csv; grep foo csv1.csv >> csv2.csv

Or, if you have already created csv2.csv:

awk 'NR==1{print ""} {print}' csv2.csv > tmpfile && mv tmpfile csv2.csv

or

perl -i -lpe 'print "" if $.==1' csv2.csv 

or

sed -i '1 x;p;x;' csv2.csv 
share|improve this answer
add comment

Use sed as follows to insert a blank line in the beginning of a file x.txt:

 sed '1 i \
 ' x.txt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.