manipulating csv to add extra row

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 07-16-2007
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  
Old 07-16-2007
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  
Old 07-16-2007
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

# 4  
Old 07-16-2007
thanks all

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

More UNIX and Linux Forum Topics You Might Find Helpful
Row Count in .csv file Prabhakar Y Shell Programming and Scripting 3 09-20-2018 01:34 PM
Add Row from First Row (Split Row) pareshkp Shell Programming and Scripting 2 11-05-2015 12:32 PM
Need to Insert three extra columns in csv file ahmed.vaghar Shell Programming and Scripting 5 09-13-2015 02:57 PM
Have problem with extra EOLs in my CSV - need help cleaning out richardsantink Shell Programming and Scripting 4 06-16-2014 06:10 PM
Randomly inserting extra columns into csv file Lokesha Shell Programming and Scripting 8 09-20-2013 02:53 PM
Help with multiple variables into one row in CSV! The_Grim_Coder Shell Programming and Scripting 3 01-16-2013 02:45 PM
To Add extra commas to a CSV file. chillblue UNIX for Dummies Questions & Answers 12 07-05-2012 09:18 AM
To Add extra commas to a CSV file using 2 files... chillblue UNIX for Dummies Questions & Answers 1 07-05-2012 09:15 AM
Adding Extra Commas to a CSV file chillblue Shell Programming and Scripting 1 07-05-2012 08:59 AM
Ascii Mode appending extra records to csv file developerpa Shell Programming and Scripting 3 06-12-2012 03:23 AM
shell script to remove extra commas from CSV outp file sreenath1037 Shell Programming and Scripting 1 04-29-2011 03:11 PM
Manipulating csv file Deepthz Shell Programming and Scripting 3 12-02-2010 04:11 AM
Help Manipulating Large Csv File xxwohxx Shell Programming and Scripting 8 09-01-2010 06:42 PM
Add value of each row when each row has different data ype made2last Shell Programming and Scripting 1 04-24-2009 02:16 AM
exporting number into .csv file in text form (no other extra charc) from shell script Deepak_Rastogi Shell Programming and Scripting 5 03-13-2008 05:08 PM