Sponsored Content
Top Forums Shell Programming and Scripting awk to delete fields from flat file Post 302870915 by Akshay Hegde on Tuesday 5th of November 2013 07:53:19 AM
Old 11-05-2013
first you try this NF prints number of fields in file

Code:
$ awk -F"|" '{print $0,NF}' OFS="|" file
ZHV|3011|D0171001|L|LPN|Z|PAN|20131104000148||||OPER||13
748|49790||3
354|902|20131029|1|2|3|4|5|6|7|8|9|10|11|12|||17
352|5759991|SP29|1200031516735|20131101||6
354|||||FLAT 2 AT||2||GARENDON ROAD|||MORDEN|SURREY|SM4 6LN|ADI0001||17
748|49792||3
352|5760019|SP27|1200021998833|20131101||6

from post #1

Code:
$ cat file
354|||||GROUND||97||JUDD STREET|||LONDON||WC1H 9JG|ADI001|
354|||||FLAT 1 ||213||STRAND|||LONDON||WC2R 1AP|ADI0001|
324|||||||491A||FULHAM ROAD|||LONDON||SW6 1HJ|ADI0001|

Code:
$ awk -F"|" '/354/{$16="\b"}1' OFS="|" file

Resulting
Code:
354|||||GROUND||97||JUDD STREET|||LONDON||WC1H 9JG|
354|||||FLAT 1 ||213||STRAND|||LONDON||WC2R 1AP|
324|||||||491A||FULHAM ROAD|||LONDON||SW6 1HJ|ADI0001|

from post #6

Code:
$ cat file
ZHV|3011|D0171001|L|LPN|Z|PAN|20131104000148||||OPER|
748|49790|
354|902|20131029|1|2|3|4|5|6|7|8|9|10|11|12||
352|5759991|SP29|1200031516735|20131101|
354|||||FLAT 2 AT||2||GARENDON ROAD|||MORDEN|SURREY|SM4 6LN|ADI0001|
748|49792|
352|5760019|SP27|1200021998833|20131101|

Code:
$ awk -F"|" '/354/{$16="\b"}1' OFS="|" file

Resulting
Code:
ZHV|3011|D0171001|L|LPN|Z|PAN|20131104000148||||OPER|
748|49790|
354|902|20131029|1|2|3|4|5|6|7|8|9|10|11|12|
352|5759991|SP29|1200031516735|20131101|
354|||||FLAT 2 AT||2||GARENDON ROAD|||MORDEN|SURREY|SM4 6LN|
748|49792|
352|5760019|SP27|1200021998833|20131101|


Last edited by Akshay Hegde; 11-05-2013 at 09:04 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk to convert a flat file to CSV file

Hi , I have a file with contents as below: Contract Cancellation Report UARCNCL LOS CODE DATE REAS TYPE AMOUNT AMOUNT LETTER BY ========= ======= ==== ==== ==== ========= ==== ==== 8174739 7641509 1S NONE CRCD 30-JUN-2008 NPAR N .00 .00 CCAN 8678696 8091709 1S NONE DDEB 30-JUN-2008... (14 Replies)
Discussion started by: rkumudha
14 Replies

2. Shell Programming and Scripting

Search flat file and return 3 fields

I need to be able to search a flat file (comma-separated values) for a specific value and then return the following 2 fields into variables. Here's a sample flat file: SN,Account,IPaddress W120394YF,adam,10.0.20.2 W394830PR,betty,10.0.20.3 W847582TD,charlie,10.0.20.4... (7 Replies)
Discussion started by: da2357
7 Replies

3. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

4. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

5. Shell Programming and Scripting

use awk to ssh from variable in flat file

flat file looks like ooss-pfgg-1234,vol_name_1, mail-list decoded = hostname,volum_name,mail_list each line has diff info am trying to ssh into each fist field, check vol usage for second field, and if greater than 90% send mail to mail-list got the second and third part working, ... (1 Reply)
Discussion started by: riegersteve
1 Replies

6. Shell Programming and Scripting

SED | Awk flat file one liner

sed awk one liner (2 Replies)
Discussion started by: jap2614
2 Replies

7. UNIX for Dummies Questions & Answers

using sed delete a line from csv file based on specific data in two separate fields

Hello, :wall: I have a 12 column csv file. I wish to delete the entire line if column 7 = hello and column 12 = goodbye. I have tried everything that I can find in all of my ref books. I know this does not work /^*,*,*,*,*,*,"hello",*,*,*,*,"goodbye"/d Any ideas? Thanks Please... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

8. Shell Programming and Scripting

Delete last 2 fields from every record in a file

Sample file record : "20130617003","2013-06-18T07:00:03","OUTWARD","01001011","TEST PLC","","HFX834346364364","20130617","10","DUM87534758","","1.28","826","020201","65879278","","","","","","010101","56789","DUMMY... (3 Replies)
Discussion started by: bigbuk
3 Replies

9. Shell Programming and Scripting

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 Input file: ZHV|2657|D0217001|T|TXU|Z|PAN|20131112000552||||OPER| 754|52479| 492|489|SP40|1014570286334|20131111|20131201|14355334|CHAMELON... (1 Reply)
Discussion started by: Aditya_001
1 Replies

10. Shell Programming and Scripting

awk Flat File Conversion Script

In awk how would I flatten input.txt to output.txt? Input: givenname: Darth sn: Vadar mail: d.vadar@deathstar.com uid: dv12345 orclguid: 1234567890 givenname: Carlito sn: Brigante mail: c.brigante@paradise.com uid: cb12345 orclguid: 2134567890 Output: ... (3 Replies)
Discussion started by: u20sr
3 Replies
All times are GMT -4. The time now is 10:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy