Last column is getting deleted


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Last column is getting deleted
# 1  
Old 09-17-2010
Last column is getting deleted

Hi,
I am having a problem in the below code:-.

Code:
$ cat x.csv
baseball,NULL,8798765,Most played,0,5,12367,NULL,NULL,98,67,Reason is not sufficient
baseball,NULL,8928192,Most played,0,4,76893,NULL,RAW,54,78,Reason is not sufficient
baseball,NULL,5678945,Most played,9,2,1,6,NULL,6789,123,Reason not conclueded
cricket,NOTNULL,125782,Usually played,NULL,NULL,NULL,NULL,123,67,Reason not conclueded
cricket,NOTNULL,678921,Usually played,NULL,NULL,NULL,NULL,563,NULL,Reason not defines


Expected output
===============
baseball,NULL,8798765,Most played,0,5,12367,NULL,NULL,98,67,Reason is not sufficient
        ,NULL,8928192,Most played,0,4,76893,NULL,RAW,54,78,Reason is not sufficient
        ,NULL,5678945,Most played,9,2,1,6,NULL,6789,123,Reason not conclueded
cricket,NOTNULL,125782,Usually played,NULL,NULL,NULL,NULL,123,67,Reason not conclueded
       ,NOTNULL,678921,Usually played,NULL,NULL,NULL,NULL,563,NULL,Reason not defines

but the output that is displayed is :-

$ nawk 'BEGIN{FS=","}!a[$1] {print;a[$1]++;next}{print FS$2FS$3FS$4FS$5FS$6FS$7FS$8FS$9FS$10FS$11FS12}' x.csv
baseball,NULL,8798765,Most played,0,5,12367,NULL,NULL,98,67,Reason is not sufficient
,NULL,8928192,Most played,0,4,76893,NULL,RAW,54,78
,NULL,5678945,Most played,9,2,1,6,NULL,6789,123
cricket,NOTNULL,125782,Usually played,NULL,NULL,NULL,NULL,123,67,Reason not conclueded
,NOTNULL,678921,Usually played,NULL,NULL,NULL,NULL,563,NULL,Reason not defines


The last column in row 2 and rown3 is getting deleted

Please somebody help me
# 2  
Old 09-17-2010
Code:
awk 'BEGIN{FS=OFS=","}!a[$1]{print;a[$1]++;next}{$1="\t"}1' x.csv

# 3  
Old 09-17-2010
Thanks very much.

Why was it not working in my code ?
Can you please explain the code that you have written

Thanks

---------- Post updated at 01:28 AM ---------- Previous update was at 01:18 AM ----------

The code is leaving a spacei.e a box sign, when i attach it and send it to my mail id
# 4  
Old 09-17-2010
In fact, I don't check your code at all. I just give you my code directly.

Normally I don't write code to list all column one by one.
# 5  
Old 09-17-2010
Ohh I resolved the issue of the space ...i replace the \t with " " and it worked...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

2. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

3. Post Here to Contact Site Administrators and Moderators

how do i get my threads deleted?

as subject - need this done asap, in trouble (1 Reply)
Discussion started by: llcooljatt
1 Replies

4. Emergency UNIX and Linux Support

Directory got deleted

One of my directory code where i have stored all my scripts have disappeared . I have no idea on how it got deleted.Could someone pls help me to track-back on what would have happened? I left the office yesterday and today when i just logged in to work with the scripts I could not find the... (13 Replies)
Discussion started by: michaelrozar17
13 Replies

5. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

6. UNIX for Advanced & Expert Users

deleted all files - rm *

Hi All, I am using Fedora Core and Windows Xp. I deleted all the files from root directory. When i am trying to restart the computer it showing some grub > prompt. What i will do ? I have lots of data in XP OS. Please help me i used # rm * (8 Replies)
Discussion started by: pritish.sas
8 Replies

7. Shell Programming and Scripting

Who deleted crontab?

We are using SunOS 5.10 and Korn Shell. If we need to figure out who deleted our crontab file for a particular user what do we do. Thanks in Advance!! ---------- Post updated at 08:08 AM ---------- Previous update was at 07:19 AM ---------- Friends, Please help.... (5 Replies)
Discussion started by: mehimadri
5 Replies

8. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

9. UNIX for Dummies Questions & Answers

deleted /usr

I accidentally deleted the usr on/. How can I start the server again? (5 Replies)
Discussion started by: rahmantanko
5 Replies
Login or Register to Ask a Question