Copying down first row in to all the below blank rows in a .csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying down first row in to all the below blank rows in a .csv file
# 8  
Old 04-03-2012
Some issue with formatting...

Hi Scrutinizer,

There is some issue in my output format. Input is the following..
Code:
SerialNo,Location,Country 
1,Delhi,India 
,Mumbai,India
,Bangalore,India
2,NewYork,USA 
,SantaClara,USA 
3,Frankfurt,Germany

Required Output is here:
Code:
SerialNo,Location,Country
 1,Delhi,India
 1,Mumbai,India
 1,Bangalore,India
 2,NewYork,USA 
 2,SantaClara,USA
 3,Frankfurt,Germany

If you notice the difference the digit '1' need to be copied down until it sees '2' , similarly '2' need to be copied until it sees next digit '3'.
Like this I need to modify all my input .csv files.

I hope I made myself clear.

Thanks

Last edited by Franklin52; 04-03-2012 at 10:39 AM.. Reason: Please use code tags for data and code samples, thank you
# 9  
Old 04-03-2012
What output are you getting?

On cygwin it seems fine:
Code:
Carlo@CRM-MT4 ~
$ cat x.txt
SerialNo,Location,Country
1,Delhi,India
,Mumbai,India
,Bangalore,India
2,NewYork,USA
,SantaClara,USA
3,Frankfurt,Germany

Carlo@CRM-MT4 ~
$ awk -F, '{$1=x$1?p=$1:p}1' OFS=, x.txt
SerialNo,Location,Country
1,Delhi,India
1,Mumbai,India
1,Bangalore,India
2,NewYork,USA
2,SantaClara,USA
3,Frankfurt,Germany

Carlo@CRM-MT4 ~
$ awk -F, 'NR>1{if($1=="")$1=p; else p=$1}1' OFS=, x.txt
SerialNo,Location,Country
1,Delhi,India
1,Mumbai,India
1,Bangalore,India
2,NewYork,USA
2,SantaClara,USA
3,Frankfurt,Germany

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] - Replace blank and string in csv file

Hi all, i have a .csv file with only two columns, like: Login;Status Luca;S Marco; Stefano; Elettra;S Laura; ... I need to replace the blank space on Status column whit Enabled end, on the same column, S whit Disabled, like: Login;Status Luca;Disabled Marco;Enabled Stefano;Enabled... (10 Replies)
Discussion started by: kamose
10 Replies

2. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

3. Shell Programming and Scripting

Detect blank spaces in a CSV file

I'm monitoring a WLAN network to keep track of new SSIDs popping up. The SSIDs are stored along with the AP MAC address and a few other parameters in a CSV file. A typical line could look like this: 18:70:9f:e3:80:aa 10:11:15 MyNetwork 2437 Now, the problem is that some networks use SSIDs... (4 Replies)
Discussion started by: Zooma
4 Replies

4. Shell Programming and Scripting

Inserting blank columns in already present CSV file

Hi, i have a csv file which have headers and values of it like below : headers --> CI Ref SerialNumber LastScanDate values --> VMware-42,VMware-42,Tue, 20 May 2014 11:03:44 +0000 i want to have a above csv in below format : headers --> CI Name CI Description CI Ref... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

5. Shell Programming and Scripting

Moving or copying first rows and last rows into another file

Hi I would like to move the first 1000 rows of my file into an output file and then move the last 1000 rows into another output file. Any help would be great Thanks (6 Replies)
Discussion started by: kylle345
6 Replies

6. Shell Programming and Scripting

Extract rows from file based on row numbers stored in another file

Hi All, I have a file which is like this: rows.dat 1 2 3 4 5 6 3 4 5 6 7 8 7 8 9 0 4 3 2 3 4 5 6 7 1 2 3 4 5 6 I have another file with numbers like these (numbers.txt): 1 3 4 5 I want to read numbers.txt file line by line. The extract the row from rows.dat based on the... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

7. Shell Programming and Scripting

How to remove Blank rows in a csv file

Hi, I need help to remove blank rows at the end of file. Sample data: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 "Tønsberg, Brygga Kino SF",Tønsberg,202-1,Tønsberg SF 4,202-1-4 ,,,, ,,,, ,,,, ,,,, Expected data: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 "Tønsberg, Brygga... (6 Replies)
Discussion started by: cnraja
6 Replies

8. Shell Programming and Scripting

Blank Space is not appending in each row of CSV File - Shell Script

I am calling SQL script in my UNIX Shell script and trying to create the CSV file and my last column value of each row is 23 blank spaces. In my SQL script,the last column is like below. RPAD(' ',23,' ') -- Padding 23 blank Spaces The CSV file is generated but the sapce(23 spaces) is... (2 Replies)
Discussion started by: praka
2 Replies

9. Shell Programming and Scripting

how to delete blank rows in a log file

Help How to delete all blank rows in log file (4 Replies)
Discussion started by: suryanarayana
4 Replies

10. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question