awk to place value at 24 field in a flat file issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to place value at 24 field in a flat file issue
# 1  
Old 11-12-2013
awk to place value at 24 field in a flat file issue

I am trying to add 0393 value at 24th feild using the below command, but its adding at all the lines including header and trailer


Code:
 
 
 
Input file:
ZHV|2657|D0217001|T|TXU|Z|PAN|20131112000552||||OPER|
754|52479|
492|489|SP40|1014570286334|20131111|20131201|14355334|CHAMELON (SOUTHEND) 5-7||||LUCY ROAD|||SOUTHEND-ON-SEA|ESSEX|SS1 2AU|86|_A|E|C|845|0||SSIL|H|SSIL|H|EELC|H|
492|490|SP40|1030027567348|20131111|20131201|14355335|||BILL CLEYNDERT AND CO LTD||FLAG STREET|||FAKENHAM|NORFOLK|NR21 7RN|86|_A|E|C|845|0||SSIL|H|SSIL|H|LOND|H|
492|51540|SP40|1012684803375|20131111|20131209|14357150|||38||LONGMEAD|||NORWICH|NORFOLK|NR1 2EL|3|_A|E|A|835|1|0393|LBSL|N|LBSL|N|LBSL|N|
ZPT|2657|10498||38|20131112000552|
Command used:
 
awk 'BEGIN{OFS=FS="|"} {$24="0393";print } ' file
I am aware we can use search operation and place the data as well something like the below
awk -F"|" '/^492/
 
 
Could any one help me to add value as 0393 at 24th feild, only for the lines that start with 492

# 2  
Old 11-12-2013
try
Code:
awk 'BEGIN{OFS=FS="|"} /^492/{$24="0393"}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with awk when joining two files when field has '-' hyphen

Dear Community; I need to join two files but I am facing issues. 1st file has multiple columns. Primary (1st) columns has unique values. There are other columns out of which some has non-ascii characters as well (other language). Example File below: 1-1001JRL,BiRecurring... (5 Replies)
Discussion started by: mystition
5 Replies

2. Shell Programming and Scripting

awk to place specific contents filename within text file

I am trying to use awk to place the contens of a filename in $1 and $2 followed by the data in the text file. Basically, put the filename within the text file. There are over 1000 files in the directory and as of now each file is saved with a unique name but it is not within the file. Thank you... (10 Replies)
Discussion started by: cmccabe
10 Replies

3. Shell Programming and Scripting

How to update field value in place?

Dear all: I have a file: 1:00 2:abc 3:12asweand I ran the following awk script on this file: #!/usr/bin/awk -f { i= 1; while(i<=NF) { $i=substr($i, 1, index($i, ":")-1); i++ } }I am expecting the file would become (after running... (7 Replies)
Discussion started by: littlewenwen
7 Replies

4. Shell Programming and Scripting

Copy a field into n line in another place

I have a file contains 100 section (here i show 2 section of that); i want to replace date from 1st & 2nd field of 1st line of each section (1st line of each section is header and the other lines are body) and merg them into one field, then copy it on 7th field of the lines in each section... (17 Replies)
Discussion started by: oreka18
17 Replies

5. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

6. UNIX for Dummies Questions & Answers

Inserting a sequential number into a field on a flat file

I have a csv flatfile with a few million rows. I need to replace a field (field number is 85) in the file with a sequential number. As an example, let's assume there are only 4 fields in the file: A,A,,32 A,A,,27 A,B,,43 C,C,,354 If I wanted to amend the 3rd field in this way my... (2 Replies)
Discussion started by: BristolSmithy
2 Replies

7. Shell Programming and Scripting

Find the position of a field/column in a flat file

Hi, Let say I have a file which has around 400 fields. SampleFile ========= PATIENTID|FACILITY|................|TIME_LAST_VISITED_BY_MD|.....|STATUS| How is it possible to find out which field is TIME_LAST_VISITED_BY_MD?fro example by seeing the above structure we can saw FACILITY... (5 Replies)
Discussion started by: machomaddy
5 Replies

8. Shell Programming and Scripting

how to add extra a field in a flat txt file ?

Hi all, I did not use UNIX for a long time, now i need to make a flat file with extra field, can you help me with the code ? 1. I create a last line of each log from each system and make it in a flat text file (seperate by a pipe |) mv current.log old tail -1 sanfrancisco.log > current.log... (5 Replies)
Discussion started by: britney
5 Replies

9. Shell Programming and Scripting

1024 field issue : awk

Hi i have a txt file in which i do a awk operation with ":" as field separator A B C D ABC::2386.13:2386.13:3248234281995::+DPY:INT:3:N::::2:200.00:0.00:2010-05-12:CA: ::2:N::N:PH:00010031:0001+DPY:BAL:3:N::::3:1601.01:0.00:2010-05-12:XT::2:N:MR ... (1 Reply)
Discussion started by: mad_man12
1 Replies

10. Shell Programming and Scripting

`find`, pulling 1st field from ASCII flat file as search/-name?

Hey Everyone! I have searched around for this on Unix.com and Google, and I'm either not phrasing my search properly or this is not as simple as I thought... I have a script that runs on a nightly basis that pulls one field worth of data from an internal MySQL database and populates to an... (2 Replies)
Discussion started by: Gecko12332
2 Replies
Login or Register to Ask a Question