Paste a word in the third field position of a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Paste a word in the third field position of a file
# 1  
Old 08-16-2009
Paste a word in the third field position of a file

Hi All,

I have a file like this,
Code:
0.0.0.1 /account 327706,Data Cleansing,[254013574295650458],[100,978,0x4],CRM error,100,0

The above line is a comma separted data file. I want to modify the third field
Code:
[254013574295650458]

to
Code:
[0.0.0.1 /event/billing/product/fee/purchase 254013574295650458]

The final data file should be like
Code:
0.0.0.1 /account 327706,Data Cleansing,[0.0.0.1 /event/billing/product/fee/purchase 254013574295650458],[100,978,0x4],CRM error,100,0

NOTE: My shell is ksh.

Could you guys help me to write a shell script for this!.
Thanks in advance.
Giri.

Use CODE tags next time please, ty.

Last edited by zaxxon; 08-17-2009 at 05:14 AM.. Reason: CODE tags
# 2  
Old 08-17-2009
Code:
$more file11
0.0.0.1 /account 327706,Data Cleansing,[254013574295650458],[100,978,0x4],CRM error,100,0
$awk ' BEGIN{ FS=","; OFS="," }
{
 sub("\[", "[0.0.0.1 /event/billing/product/fee/purchase ", $3)	;
 print $0
}


Result:
0.0.0.1 /account 327706,Data Cleansing,[0.0.0.1 /event/billing/product/fee/purchase 254013574295650458],[100,978,0x4],CRM error,100,0

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Update a specific field in file with Variable value based on other Key Word

I have an input file with A=xyz B=pqr I would want the value in Second Field (xyz or pqr) updated with a value present in Shell Variable based on the value passed in the first field. (A or B ) while read line do NEW_VALUE = `some functionality done on $line` If $line=First Field-... (1 Reply)
Discussion started by: infernalhell
1 Replies

2. Shell Programming and Scripting

Bash copy and paste text in file from one position to another

Hi I have a text file with lines beginning with 71303, 71403, 71602, I need to copy the 10 digit text at position 30 on lines beginning with 71303 (5500011446) to position 99 on every line beginning with 71602 (see example below), There may be many 71303 lines but I need the text copying to... (2 Replies)
Discussion started by: firefox2k2
2 Replies

3. Shell Programming and Scripting

Write a word at 72nd position of a matched line in a file

Hi, I need to search a file for a pattern,replace some other word and write a word at its 72nd position. For example, My name is Mano.Im learning Unix. I want to search the file in all lines containing the word "Mano".In that matched line,replace the word "Unix" with "Java".And... (5 Replies)
Discussion started by: mano1 n
5 Replies

4. Shell Programming and Scripting

Grep the 5th and 6th position character of a word in a file

I am trying to find/grep the 5th and 6th position character (TX) of a word in a file. I tried to do grep "....TX" file The output gives me everything in the file with TX in it. I only need the output with the TX in the 5th and 6th position of the word. Any idea Example: test1 car... (5 Replies)
Discussion started by: e_mikey_2000
5 Replies

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

6. UNIX for Dummies Questions & Answers

Script to delete a word based on position in a file

Hi, I am new to unix. I want to delete 2 words placed at position say for example at 23rd and 45th position in a line. I used sed but couldnt achieve this. Example: the file contains 2 lines 12345 98765 "12345" 876 12345 98765 "64578" 876 I want to delete " placed at position 13 and 19... (4 Replies)
Discussion started by: nbks2u
4 Replies

7. Shell Programming and Scripting

How to put a word starting at particular position in a file using shell scripting

Hi all, I'm new to shell scripting and hence this query. I have 2 files. temp.txt and config.txt. The values in temp.txt are tab separated. ex: temp.txt AB CDE GHIJ OPQRS WXY ex:config.txt (1st line for 1st element of temp.txt and so on) start = '1' end='5' start = '6' end =... (26 Replies)
Discussion started by: subhrap.das
26 Replies

8. Solaris

Copy and paste text from a word document into a txt file in vi

Hello, Can anybody please tell me how we can copy and paste text from a word document into a text file that we are editing in vi? Is it possible to do that while we are editing the text file in vi in insert mode? Thanks, (3 Replies)
Discussion started by: Pouchie1
3 Replies

9. Shell Programming and Scripting

To trim Certain field in a line of a file and replace the new string in that position

To trim 3rd field in for all the lines of a file and replace the modified string in that particular field. For example i have a file called Temp.txt having content Temp.txt ----------------- 100,234,M1234 400,234,K1734 300,345,T3456 ---------------- So the modified file output should... (4 Replies)
Discussion started by: rpadhi
4 Replies

10. Shell Programming and Scripting

How to check a word position in a file ?

Hello everybody, I have a file like this : "window 1 truck 3 duck 2... fire 1... etc..." and I would like to print the following number of a word I am searching for. (For example here, if I search for the word "fire", I will print "1") Thank you for your help ! (7 Replies)
Discussion started by: tibo
7 Replies
Login or Register to Ask a Question