Inserting a new field inbetween two exisitng field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting a new field inbetween two exisitng field
# 1  
Old 01-03-2012
Inserting a new field inbetween two exisitng field

I have a '|' delimited file.

My file looks like below

23|nationalhoilday|feb12||||||||||||||california|northdistrict||

In the same way, each record has 164 fields. I have to insert one more field after the 85th field.

Expected output
23|nationalhoilday|feb12||||||||||||||california||northdistrict||

Someone please help me with this.
# 2  
Old 01-03-2012
Try with this ..
Code:
$ nawk 'BEGIN{FS="|";OFS="|"} {$85="some content|"$85; print}' infile

# 3  
Old 01-03-2012
Quote:
Originally Posted by machomaddy
I have to insert one more field after the 85th field.
Try:
Code:
awk -F"|" '{$85=$85 FS}1' OFS="|" file

# 4  
Old 01-03-2012
nawk is not working for me. I get an error

Code:
-bash: nawk: command not found

---------- Post updated at 03:14 PM ---------- Previous update was at 03:09 PM ----------

Franklin52: Thanks!! It woked Smilie

Jayan Jay:
Used gawk instead of nawk, it worked. Smilie

Code:
$ gawk 'BEGIN{FS="|";OFS="|"} {$85="some content|"$85; print}' infile

Thanks guys both of the codes work!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting a field without disturbing field separator on other fields

Hi All, I have the input as below: cat input 032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies

2. UNIX for Dummies Questions & Answers

Inserting the last field first

I have a list of more than 1000 files on the following format. roman_pottery_in_the_archaeological_record_2007.pdf power_politics_and_religion_in_timurid_iran_2007.pdf toward_a_theory_of_human_rights_religion_law_courts_2006.pdf i_was_wrong_the_meanings_of_apologies_2008.pdf I want to... (2 Replies)
Discussion started by: kristinu
2 Replies

3. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

4. Shell Programming and Scripting

Inserting some text if a field in the last column changes

Hi, I have a file which looks like this: A 01 00 B 02 00 C 04 00 D 00 01 E 01 01 F 02 01 G 01 04 H 02 04 I want to insert some text if the field if the last column changes. It should look like this: Value 00 A 01 00 B 02 00 C 04 00 Value 01 (6 Replies)
Discussion started by: wenclu
6 Replies

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

6. Shell Programming and Scripting

Inserting string in between field in comma separated file

Hello Mates, I have one txt file having commo seperated values. I have to insert string "FALSE" in 2nd field from the end. E.G SE18 6RN,,,,5439070,1786840,,1000002148671600,123434 Out put should be: SE18 6RN,,,,5439070,1786840,FALSE,1000002148671600,123434 Can some one help me to... (8 Replies)
Discussion started by: krsnadasa
8 Replies

7. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

8. Shell Programming and Scripting

ORA-01756 Error while inserting a file in CLOB field

Hi, Please guide me where i am doing wrong, i am getting ORA-01756:quoted string not properly terminated when i am trying to insert file into CLOB cloumn of Oracle DB. Please find below the code where log file variable is myLogFile. Please let me know where i am doing wrong. ... (0 Replies)
Discussion started by: rajeshorpu
0 Replies

9. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

10. Shell Programming and Scripting

Question about sed. Inserting text in field?

Hi, I have tried to develop a sed script that inserts date and time in the third field in the first and second row below. The third row is an example and it shows where the date and time should be inserted. The script should check if the row already has date and time in the third field and if it... (2 Replies)
Discussion started by: pcrs
2 Replies
Login or Register to Ask a Question