using awk to substitute data in a column delimited text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using awk to substitute data in a column delimited text file
# 1  
Old 05-31-2011
using awk to substitute data in a column delimited text file

using awk to substitute data in a column delimited text file

hello i would like to use awk to do the following calculation from the following snippet.

input file

Code:
C;2390   ;CV BOUILLOTTE 2L 2FACES NERVUREES            ;1.00       ;3552612239004;13417  ;25     ;50     ;   12;50000   ; ;     ;0       ; ;     ;0       ;
C;2400   ;BL 125 EPINGLES DE SURETE                    ;.46        ;3552611240001;10032  ;24     ;240    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2410   ;BL KIT DE COUTURE                            ;.68        ;3552611241008;9816   ;24     ;48     ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2510   ;CV 3 POTS ENV 150 PICS COCKTAIL BOIS         ;.36        ;3552612251006;2918   ;24     ;288    ;   12;18144   ; ;     ;0       ; ;     ;0       ;
C;2511   ;CV 5 ETUIS ENV 150 PICS COCKTAIL BOIS        ;.46        ;3552612251105;0      ;24     ;144    ;   12;18144   ; ;     ;0       ; ;     ;0       ;
C;2513   ;CV 2 DISTRIBUTEURS 200 PICS COCKTAIL BOIS    ;.46        ;3552612251303;13944  ;24     ;144    ;   12;8640    ; ;     ;0       ; ;     ;0       ;
C;2515   ;CV ENV 100 BROCHETTES BBQ BOIS 30CM          ;.46        ;3552612251501;15300  ;50     ;100    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2517   ;CV ENVIRON 100 PICS BROCHETTES BAMBOU 30CM   ;.50        ;3552612251709;0      ;50     ;100    ;   12;20000   ; ;     ;0       ; ;     ;0       ;
C;2518   ;PBH SACHET DE 40 PAILLES CHALUMEAU FLEXIBLES ;.10        ;3552612251808;49743  ;50     ;250    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2520   ;VRC MARTINET                                 ;.60        ;3552610252005;56484  ;36     ;216    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2522   ;CV 3 LAVETTES MICROFIBRES 30X30CM  MAGIC     ;.72        ;3552615252208;4498   ;24     ;144    ;   12;15120   ; ;     ;0       ; ;     ;0       ;


output file
Code:
C;2390   ;CV BOUILLOTTE 2L 2FACES NERVUREES            ;3.00        ;3552612239004;13417  ;25     ;50     ;   12;50000   ; ;     ;0       ; ;     ;0       ;
C;2400   ;BL 125 EPINGLES DE SURETE                    ;2.46        ;3552611240001;10032  ;24     ;240    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2410   ;BL KIT DE COUTURE                            ;2.68        ;3552611241008;9816   ;24     ;48     ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2510   ;CV 3 POTS ENV 150 PICS COCKTAIL BOIS         ;2.36        ;3552612251006;2918   ;24     ;288    ;   12;18144   ; ;     ;0       ; ;     ;0       ;
C;2511   ;CV 5 ETUIS ENV 150 PICS COCKTAIL BOIS        ;2.46        ;3552612251105;0      ;24     ;144    ;   12;18144   ; ;     ;0       ; ;     ;0       ;
C;2513   ;CV 2 DISTRIBUTEURS 200 PICS COCKTAIL BOIS    ;2.46        ;3552612251303;13944  ;24     ;144    ;   12;8640    ; ;     ;0       ; ;     ;0       ;
C;2515   ;CV ENV 100 BROCHETTES BBQ BOIS 30CM          ;2.46        ;3552612251501;15300  ;50     ;100    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2517   ;CV ENVIRON 100 PICS BROCHETTES BAMBOU 30CM   ;2.50        ;3552612251709;0      ;50     ;100    ;   12;20000   ; ;     ;0       ; ;     ;0       ;
C;2518   ;PBH SACHET DE 40 PAILLES CHALUMEAU FLEXIBLES ;2.10        ;3552612251808;49743  ;50     ;250    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2520   ;VRC MARTINET                                 ;2.60        ;3552610252005;56484  ;36     ;216    ;     ;0       ; ;     ;0       ; ;     ;0       ;
C;2522   ;CV 3 LAVETTES MICROFIBRES 30X30CM  MAGIC     ;2.72        ;3552615252208;4498   ;24     ;144    ;   12;15120   ; ;     ;0       ; ;     ;0       ;


which would mean adding 2 to the fourth column of each entry of the file.

i have been looking around the forum but so far did not find anything.

Thanking you in advance for your help on this matter.
# 2  
Old 05-31-2011
Code:
awk -F";" '{$4+=2}1' OFS=";" filename

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 05-31-2011
Try:
Code:
awk -F\; -vOFS=";" '{$4+=2;$4=$4"\t"}1' file

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 05-31-2011
Thank you for all your replies, i have come up with the following answer to the problem

Code:
awk -v FS=";" -v OFS=";\t" -v RS="\r" '{print $1,$2,$3,$4+2,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16}' input > output

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append data to first column delimited file

Hi, I have a data like Input: 12||34|56|78 Output: XYZ|12||34|56|78 I tried like this , but it puts it on another line awk -F "|" ' BEGIN {"XYZ"} {print $0} 'file Any quick suggessitons in sed/awk ? am using HP-UX (3 Replies)
Discussion started by: selvankj
3 Replies

2. Shell Programming and Scripting

awk to substitute third column if first column is greater than interest

A file 2400 2800 PSC000289 3200 3896 PCS000289 3333 3666 PCS000221 222 1000 PCS000222 3299 3600 PSC000289 Question is while if third column is PCS000289 and first column should be greater than 3000, then replace PCS000289 by YES, remaining the others column same. ... (1 Reply)
Discussion started by: cdfd123
1 Replies

3. UNIX for Dummies Questions & Answers

Extracting rows from a space delimited text file based on the values of a column

I have a space delimited text file. I want to extract rows where the third column has 0 as a value and write those rows into a new space delimited text file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

4. UNIX for Dummies Questions & Answers

Adding tags to a specific column of a space delimited text file

I have a space delimited text file with two columns. I would like to add NA to the first column of the text file. Input: 19625 10.4791768259 19700 10.8146489183 19701 10.9084026759 19702 10.9861346978 19703 10.9304364984 Output: NA19625 10.4791768259 NA19700 10.8146489183... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Moving a column across a delimited data file

Hi, I am trying to move a column from one position to another position in a delimited file. The positions are dynamic in nature and are available by environmental variables. Also the file can have n number of columns. Example: Initial Column Position=1 Final Column Position=3 Delimiter='|' ... (2 Replies)
Discussion started by: ayan153
2 Replies

6. UNIX for Dummies Questions & Answers

Using awk to log transform a column in a tab-delimited text file?

How do I use awk to log transform the fifth column of a tab-delimited text file? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. UNIX for Dummies Questions & Answers

Add a new column to a tab delimited text file

I want to add a new column to a tab delimited text file. It will be the first column and it will just be 1's. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

8. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

9. Shell Programming and Scripting

Extracting a portion of data from a very large tab delimited text file

Hi All I wanted to know how to effectively delete some columns in a large tab delimited file. I have a file that contains 5 columns and almost 100,000 rows 3456 f g t t 3456 g h 456 f h 4567 f g h z 345 f g 567 h j k lThis is a very large data file and tab delimited. I need... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

10. Shell Programming and Scripting

Delete first column in tab-delimited text-file

I have a large text-file with tab-delimited genetic data that looks like: KSC112 KSC234 0 0 1 1 A G C T I simply wan to delete the first column, but since the file has 600 000 columns, it is not possible with awk (seems to be limited at 32k columns). Does anyone have an idea how to do this? (2 Replies)
Discussion started by: andmal
2 Replies
Login or Register to Ask a Question