manipulating csv to add extra row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting manipulating csv to add extra row
# 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to Insert three extra columns in csv file

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 ... (5 Replies)
Discussion started by: ahmed.vaghar
5 Replies

2. Shell Programming and Scripting

Have problem with extra EOLs in my CSV - need help cleaning out

Hi Everyone, Searching the forum, I came across another closed thread, that appears to be either the same problem, or very close to what I'm experiencing. Closed thread for reference is at: https://www.unix.com/shell-programming-and-scripting/241664-removing-cr-lf-till-number-fields-full.html ... (4 Replies)
Discussion started by: richardsantink
4 Replies

3. Shell Programming and Scripting

Randomly inserting extra columns into csv file

Hi Tech Guru, I have a test file as below , which needs some more fields to be populated randomly : dks3243;12;20130823;1420;25m;0;syt dks3243;rocy;10 dks3243;kiop;18 sde21p4;77;20151210;8479;7py;9;vfr sde21p4;temp;67 sfq6i01;12;20120123;3412;4rd;7;jui sfq6i01;uymk;90 sfq6i01;kiop;51 ... (8 Replies)
Discussion started by: Lokesha
8 Replies

4. UNIX for Dummies Questions & Answers

To Add extra commas to a CSV file.

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,,... (12 Replies)
Discussion started by: chillblue
12 Replies

5. UNIX for Dummies Questions & Answers

To Add extra commas to a CSV file using 2 files...

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... (1 Reply)
Discussion started by: chillblue
1 Replies

6. Shell Programming and Scripting

Adding Extra Commas to a CSV file

Trying in this forum. Not sure if it is permitted.... but in need of help. Please find the requirements in the below link. https://www.unix.com/unix-dummies-questions-answers/191503-add-extra-commas-csv-file-2.html#post302665179 Thanks in Advance. (1 Reply)
Discussion started by: chillblue
1 Replies

7. Shell Programming and Scripting

Ascii Mode appending extra records to csv file

I am relatively new to this forum and Unix scripting. ksh script: part 1 :will call a PL\SQL program will create 3 CSV file at the unix directory. part 2 : will sftp the files to the EFT server. Once the EFT server receives these file , it will transfer them to a shared windows folders. ... (3 Replies)
Discussion started by: developerpa
3 Replies

8. Shell Programming and Scripting

shell script to remove extra commas from CSV outp file

Name,,,,,,,,,,,,,,,,,,,,Domain,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Contact,Phone,Email,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Location -----------------------,------------------------------------------------,-------,-----,---------------------------------,------------------------------------ ----... (1 Reply)
Discussion started by: sreenath1037
1 Replies

9. Shell Programming and Scripting

Manipulating csv file

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? (3 Replies)
Discussion started by: Deepthz
3 Replies

10. Shell Programming and Scripting

Help Manipulating Large Csv File

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... (8 Replies)
Discussion started by: xxwohxx
8 Replies
Login or Register to Ask a Question