Column name Problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Column name Problem
# 1  
Old 07-22-2009
Column name Problem

Hi,

I have a Comma seperated file of 20 columns, 2 of the column has names as "Name, Last " and "Name, First " . I want to count the no of Columns. to see if we recieved all the 20 columns or not.
when i am using the below code its giving me an error. Please Help

Code:
`head -1 Detail_$FILE_NAME | awk -F "," '{print NF }'`

Thanks
# 2  
Old 07-22-2009
Don't use backticks (`) if you want to print the result of the command.

Regards
# 3  
Old 07-22-2009
what errors are you getting?

also please keep in mind the "Name, First" will be counted as two fields by awk when you use "," as FS.
# 4  
Old 07-22-2009
I want it to be counted as one....
From that code i am getting the count of Columns as 22 where as it should be 20. I want to know if there is any way that we can consider the value with in the double codes as one field
# 5  
Old 07-22-2009
it is 22 because first part of the first field and the second part of the last field is treated as two fields by awk.

what is the separator between the fileds? is it a tab ( \t )?
if yes, then set the FS to "\t".
# 6  
Old 07-22-2009
I have the column names like this
Type,Number,Number,DOB,"Name, Last","Name, First",Gender,SubscriberID,Sub_Sequence Number,Member Number,Corporate Entity Code

I want to change the Column names as

Type,Number,Number,DOB,Name Last,Name First,Gender,SubscriberID,Sub_Sequence Number,Member Number,Corporate Entity Code

Can someone please help
# 7  
Old 07-22-2009
I believe there is a similar question here:

https://www.unix.com/shell-programmin...flat-file.html

Or perhaps you could change your field separator to something other than comma (like pipe)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem loading default date column in sqlldr

Hi All, My control file looks like: LOAD DATA APPEND INTO TABLE MK9210_PROD_DL.MK9210_PROD_EG_6 FIELDS TERMINATED BY '|' TRAILING NULLCOLS ( STUDY CHAR ,PATIENT INTEGER EXTERNAL ,CPEVENT CHAR ,NAMEG CHAR ,REFIDEG CHAR ,POSEG CHAR ,METHEG CHAR ,EGDAT CHAR ,EGTIM CHAR ,COMEG CHAR... (4 Replies)
Discussion started by: Pratiksha Mehra
4 Replies

2. Shell Programming and Scripting

Problem facing to compare different column and print out record with smallest number

Hi, Input file 1 : 37170 37196 77 51 37174 37195 73 52 37174 37194 73 53 Desired Output file 1 : 37170 37196 77 51 Input file 2 : 37174 37195 73 0 37170 37196 77 0 Desired Output file 2 : 37174 37195 73 0 (1 Reply)
Discussion started by: cpp_beginner
1 Replies

3. Shell Programming and Scripting

Problem to print out record got smallest number in specific column

Hi, Anybody know how to print out the record that shown smallest number among column 3 and column 4 Case 1 Input : 37170 37196 77 51 37174 37195 73 52 37174 37194 73 53 Case 1 Output : 37170 37196 77 51 Case 2 Input : 469613 469660 73 ... (4 Replies)
Discussion started by: cpp_beginner
4 Replies

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

awk pattern matching problem -not recognizing a column

Hi all, I am new to awk. I want to print the line numbers if the column has a particular value. For example I have: cat FILE1 COL1 COL2 X114 0 X116 0 X117 0 X120 0 X121 0 X125 0 X126 0 X127 0 X131 1 X132 0 X135 0 X136 0 (3 Replies)
Discussion started by: newpro
3 Replies

8. Shell Programming and Scripting

Problem with reading a specific column in unix

Hi I have 3 problems. 1)I have to read the 16th column of a record in a comma seperated text file in a shell script . i am trying to use ... va =( echo $line | awk -F'' '{print $16}') 2) I need to create a log and error record for each of the sql commands executed in unix. 3)... (4 Replies)
Discussion started by: sailaja_80
4 Replies

9. Shell Programming and Scripting

problem while adding column values in awk

Hi, I have a file "input.txt" with the following content : 5312,0,,,1,8,141.2,20090727 3714,0,,,1,8,285.87,20090727 5426,0,,,1,8,3.9,20090727 3871,0,,,1,8,30.4,20090727 9071,0,,,1,8,146.2,20090727 5141,0,,,1,8,2.8,20090727 0460,0,,,1,8,-0.1,20090727 7918,0,,,1,8,-0.1,20090727... (3 Replies)
Discussion started by: valokv
3 Replies

10. 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
Login or Register to Ask a Question