Column manipulation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Column manipulation
# 1  
Old 01-06-2014
Column manipulation

Hallo Team,

I have a .csv file. I would like to have another column called Prefix. Under column Prefix i would like to have the first 3 numbers from the theird column.


Code:
Other Licenced Operator    Alpha Code    Numbering    Per minute Interconnect Fee per rate group (R Excluding VAT)           
                
            Peak    Off-Peak
Amatole    ATN    085300    0.25    0.25
Amatole    ATN    085301    0.25    0.25
Cell C    CLC    0610    0.50    0.50
Cell C    CLC    0611    0.50    0.50
Cell C    CLC    0612    0.50    0.50
Cell C    CLC    0613    0.50    0.50
Cell C    CLC    0615    0.50    0.50
Cell C    CLC    074    0.50    0.50
Cell C    CLC    084    0.50    0.50
MTN    MTN    0603    0.46    0.46
MTN    MTN    0604    0.46    0.46
MTN    MTN    0605    0.46    0.46
MTN    MTN    0710    0.46    0.46
MTN    MTN    0717    0.46    0.46
MTN    MTN    0718    0.46    0.46
MTN    MTN    0719    0.46    0.46
MTN    MTN    073    0.46    0.46
MTN    MTN    078    0.46    0.46
MTN    MTN    0810    0.46    0.46
MTN    MTN    083    0.46    0.46
MTN    MTN    087260    0.27    0.27
MTN    MTN    087740    0.27    0.27
MTN    MTN    087741    0.27    0.27
MTN    MTN    087742    0.27    0.27
MTN    MTN    0878450    0.27    0.27
MTN    MTN    0878451    0.27    0.27
Neotel    NEO    080010002    0.06    0.06
Neotel    NEO    080010003    0.06    0.06
Neotel    NEO    080010004    0.06    0.06


Last edited by bartus11; 01-06-2014 at 09:58 AM.. Reason: Changed ICODE to CODE tags.
# 2  
Old 01-06-2014
CSV file?

The file you pasted does not appear to be csv. I did not see any commas.
# 3  
Old 01-06-2014
Can you show us your expected output, for give input.
# 4  
Old 01-06-2014
This is my expected output below:

Code:
Other Licenced Operator    Alpha Code    Numbering    Per minute Interconnect Fee per rate group (R Excluding VAT)      Prefix     
                
            Peak    Off-Peak
Amatole    ATN    085300    0.25    0.25   085
Amatole    ATN    085301    0.25    0.25   085
Cell C    CLC    0610    0.50    0.50    061
Cell C    CLC    0611    0.50    0.50    061
Cell C    CLC    0612    0.50    0.50    061
Cell C    CLC    0613    0.50    0.50    061
Cell C    CLC    0615    0.50    0.50    061
Cell C    CLC    074    0.50    0.50    074
Cell C    CLC    084    0.50    0.50    084
MTN    MTN    0603    0.46    0.46    060
MTN    MTN    0604    0.46    0.46    060
MTN    MTN    0605    0.46    0.46    060
MTN    MTN    0710    0.46    0.46    071
MTN    MTN    0717    0.46    0.46    071
MTN    MTN    0718    0.46    0.46    071
MTN    MTN    0719    0.46    0.46    071
MTN    MTN    073    0.46    0.46    073
MTN    MTN    078    0.46    0.46    078
MTN    MTN    0810    0.46    0.46  081
MTN    MTN    083    0.46    0.46   083
MTN    MTN    087260    0.27    0.27  087
MTN    MTN    087740    0.27    0.27  087
MTN    MTN    087741    0.27    0.27  087
MTN    MTN    087742    0.27    0.27  087
MTN    MTN    0878450    0.27    0.27   087
MTN    MTN    0878451    0.27    0.27   087
Neotel    NEO    080010002    0.06    0.06  080
Neotel    NEO    080010003    0.06    0.06  080
Neotel    NEO    080010004    0.06    0.06  080


Last edited by bartus11; 01-06-2014 at 11:16 AM.. Reason: Please use CODE tags for multiline output, not ICODE.
# 5  
Old 01-06-2014
Your file is not comma separated

for given input this should work

Code:
$ awk 'NR==1{$0=$0 OFS "Prefix"}1' file

if your real data is comma separated use following

Code:
$ awk 'NR==1{$0=$0 OFS "Prefix"}1' OFS="," file

This User Gave Thanks to Akshay Hegde For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Column manipulation

Hi, I's like to ask for help with the following question: this is an example file: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 I need to have it re-arranged in the following manner: first 2 columns, zero, zero, last two columns, columns 3 to... (6 Replies)
Discussion started by: zajtat
6 Replies

2. UNIX for Advanced & Expert Users

Column manipulation of a file

In a space delimited file how would you go about removing 2 and 3 column of a file and add "word" to the first column of the file in both awk and vi? (2 Replies)
Discussion started by: cokedude
2 Replies

3. Shell Programming and Scripting

Column manipulation and counter

Hello, I was wondering how I could change this input: cat f1 to produce this output: As you can tell, I have several unsorted repeating strings in col1 of the input file. Each of these strings has an associated word in col2. Col2 has a total of 4 possible words (go, stop,... (3 Replies)
Discussion started by: verse123
3 Replies

4. Shell Programming and Scripting

Column manipulation

Hi, I have an input file in which I need to add a column with the value of part of another column. I.e. I have the following line (example, not the actual data): field1,field2,field3,test12,field5,field6I need to get the last two characters of the 4th field, and add them at the end as a... (5 Replies)
Discussion started by: Subbeh
5 Replies

5. UNIX for Dummies Questions & Answers

Adding a column to a text file based on mathematical manipulation

Hi, I have a tab delimited text file with three different columns. I want to add an extra column to the text file. The extra column will be the second column and it will equal third column - 1. How do I go about doing that? Thanks! Input: chr1 788822 rs11240777 chr1 1008567 rs9442372... (2 Replies)
Discussion started by: evelibertine
2 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Column manipulation

Hi Everyone, I was wondering if someone could help me to transform my data into a format I need. Here is an example of what my data looks like E F G H A 1 2 3 4 B 5 6 7 8 C 9 1 2 3 D 4 5 6 7 and this is what I would need it to look like: AE 1 BE 5 CE 9 DE 4 AF 2 BF 6 CF 1 (6 Replies)
Discussion started by: zajtat
6 Replies

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

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. Shell Programming and Scripting

Flat File column manipulation

Hi All, I have a tab delimited input file with say 4 fields (columns) as below : 0000443 1AGPR061 2006 Daiml 0002198 1B3XG0K2 1989 Chdds 0002199 1Bd64J0L 1990 Ch34s 0002275 1B3s4J0K 1989 Chadys 0002276 1B465302 2002 Dageml 0002290 1B45430K 1989 Cays I want the 2nd column in file to... (5 Replies)
Discussion started by: net
5 Replies

10. Shell Programming and Scripting

File Manipulation (Move Column Position)

Hi All, I have a comma separated value (.CSV) file like the one below. The file contains about 20000 lines. FileName EmpNo,Name,Age,Sex,Band,Spouse,Children,Salary, 1000,Arnold,24,M,B,N.A.,No,10000, 1001,Jenny,27,F,C,John,2,20000, ................................... What i need is to... (1 Reply)
Discussion started by: ultimate
1 Replies
Login or Register to Ask a Question