manipulating csv to add extra row


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
manipulating csv to add extra row

hi

how do i manipulate .csv file to add an extra row after each row using shell script?

I need a blank line added for each 1000 records in my file?

I will then need to copy and paste some data in the blank row created.

thanks 4 ur support
neil
# 2  
To add a blank line:

Code:
awk 'NR%1000==0?$0=$0"\n":1' infile

To add some text:

Code:
awk 'NR%1000==0?$0=$0"\nText to be inserted":1' infile

Use nawk on Solaris.
# 3  
Code:
#!/bin/ksh

cntLoop=1
INP_CSV_FILE=$1
OUT_CSV_FILE="$HOME/outfile.csv"
rm -f $OUT_CSV_FILE
for line in `cat $INP_CSV_FILE`
do
        echo $line >> $OUT_CSV_FILE
        echo "Test,Your row here" >> $OUT_CSV_FILE # Addition of a row after each row in CSV
        if [[ $cntLoop -eq 500 ]]       # Addition of a blank line after 1000 records of the output
        then
                echo >> $OUT_CSV_FILE
                cntLoop=0
        fi
        cntLoop=$((cntLoop+1))
done

Code:

Code:
ksh compute_csv.ksh infile

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Need to Insert three extra columns in csv file
ahmed.vaghar
Hello Experts, I got a requirement i have a input file which am getting from different source,Now i want to add extra 3 columns to this file like BASE,ACTUAL and DATE. Input File Looks like QUAL CHGE TYP LAW COM1 COM2 A 1 X SED HO ASE B 3 Z CDE SE ...... Shell Programming and Scripting
5
Shell Programming and Scripting
To Add extra commas to a CSV file.
chillblue
Hi All, I got this requirement to process a complex CSV file. Eg File. Line 1: Name:,XYz Line 2: Age:,15 Line 3: Grade:,7 Line 4: Line 5: English, Maths, Science,Spanish Line 6:10,11,13,14 As you can see the maximum column is 4 . The file i need to make is Line 1: Name:,XYz,,...... UNIX for Dummies Questions & Answers
12
UNIX for Dummies Questions & Answers
To Add extra commas to a CSV file using 2 files...
chillblue
Hi , Based on my previous requirement the code works fine for comma as delimiter. Now my Req is widened up a bit .. There will be two set of files .. one with comma as delimiter and other with semi-colon ; as delimiter. Second Sample file. With Double Quotes (Semi-Colon...... UNIX for Dummies Questions & Answers
1
UNIX for Dummies Questions & Answers
Manipulating csv file
Deepthz
We need to convert a field in a csv file which is in cents to dollars.(divide by 100) in our shell script. Can some body help me?... Shell Programming and Scripting
3
Shell Programming and Scripting
Help Manipulating Large Csv File
xxwohxx
Hello everyone, I am trying to manipulate a large .csv file where I have output similar to the following - http://imgur.com/TEXD8.png The result that I am looking for would be to consolidate the first column, but combine the second and third column so it still relates to the first. I...... Shell Programming and Scripting
8
Shell Programming and Scripting