Remove " character from 25th position in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove " character from 25th position in file
# 1  
Old 09-27-2012
Remove " character from 25th position in file

Hi All,
I want to remove " character if present in position 25th in CSV file. Each field in CSV file is separated by , and enclosed in "" (enclosed using double quotes)
For example
"1","2","3",........."123 Tom " is Good boy","26",........"45"
Where "1" first position character, ...... 25th position Text = "123 Tom " is Good boy"
Here i want to remove " and Expected output must be 25th position Text = "123 Tom is Good boy"

So just want to remove additional " character from 25th position if present.
Any help is appreciated.

Last edited by lancesunny; 09-27-2012 at 04:25 PM..
# 2  
Old 09-27-2012
Code:
awk -F\, 'BEGIN{OFS=FS} {gsub(/"/,"",$25);sub(/.*/,"\"&\"",$25)}1' input_file


Last edited by msabhi; 09-27-2012 at 04:25 PM..
This User Gave Thanks to msabhi For This Post:
# 3  
Old 09-27-2012
This one removed all characters from position 25th

This one removed all characters from position 25th position
Here is what happened
Before command:-
"Sandy is "Good Boy"
After Code:
Code:
awk -F\, 'BEGIN{OFS=FS} {$25="";gsub(/,,/,",");}1' input_file

Output:- Removed all characters from position 25th.
Expected Result:- "Sandy is Good Boy"
thanks,

Last edited by radoulov; 09-27-2012 at 04:34 PM..
# 4  
Old 09-27-2012
I am extremely sorry for that...please see the updated code...
This User Gave Thanks to msabhi For This Post:
# 5  
Old 09-27-2012
Work like Charm

Thanks a lot asabhi.....
Your updated code worked like charm.Smilie
You are the man......
# 6  
Old 09-27-2012
Nooo nothing like that... i am nothing in front of gurus in this forum from whom i learnt and learning...
# 7  
Old 09-27-2012
Hey There,
Can you please explain syntax wise how we fixed this issue.
this will help me if similar replacement needs to be done on other character position wise.
You made my day man.
Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove a word that ends with special character "!"

Hi all. I want to use sed to remove a word that ends with "!" in the first page of a file. The word I want to remove is: "DNA!". I have search for an answer and nothing of what I found helped me. ~faizlo (2 Replies)
Discussion started by: faizlo
2 Replies

2. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

3. Shell Programming and Scripting

Remove word after special character "/"

Hi There, I have one requirement to remove word after character "/". Input file is 2017-07-12|02|user1l|domain1/userl|0 2017-07-12|02|user2|domain1/user2|5 2017-07-12|02|user3|domain2/user3|0 2017-07-12|02|user4|domain1/user4|432 and require OP file is ... (2 Replies)
Discussion started by: anshu ranjan
2 Replies

4. Emergency UNIX and Linux Support

Replace nth position character of all the lines in file

I want to replace 150th character of all the lines in a file using sed or awk... searched the forums but didn't find exact answer (9 Replies)
Discussion started by: greenworld123
9 Replies

5. Linux

Linux script to remove a character in a file based on position.

Greetings, We have a requirement where we need to loop in a fixed width file in linux and remove a character based on a position for every record. It would highly appreciate if someone can help to automate this. Appreciate your time and help! Regards (3 Replies)
Discussion started by: mailme0205
3 Replies

6. UNIX for Advanced & Expert Users

Remove lines if the first character is "|"

Hi. I have a huge file (350 million lines). I need to delete all lines in it that: 1. Begin with a pipe character -- '|' 2. Or have less than 5 pipe characters in the line Have been searching for some SED/AWK help for this (which is faster btw on such a ginormous file?) but only... (7 Replies)
Discussion started by: pkiula
7 Replies

7. Shell Programming and Scripting

How to remove a semi-repeating character in position 1 of a file

My file is in a good column format but several lines in the file begin with a zero. I'm in KSH and looking for a command to remove this zero and keep the text next to it. I don't want any of the zeros in the other columns removed. Below is a snip from the file... all I need to do is remove that... (2 Replies)
Discussion started by: right_coaster
2 Replies

8. Shell Programming and Scripting

How to find character position in file?

how to find character positionin file? i.e string = "123X568" i want to find the position of character "X". Thanks (6 Replies)
Discussion started by: LiorAmitai
6 Replies

9. UNIX for Dummies Questions & Answers

Sort file by character position

Hi! I need to sort file by certain column (column position from-to). I tried sort command, but it works wrong. Example: 0001 5214521 0148 6712145 I need to sort this 2 lines by values from position 9 to 12 (bold) Output: 0148 6712145 0001 5214521 Is there any way how to do this? (2 Replies)
Discussion started by: nadinnne
2 Replies

10. Shell Programming and Scripting

Insert character in a specific position of a file

Hi, I need to add Pipe (|) at 5th and 18th position of all records a file. How can I do this? I tried to add it at 5th position using the below code. It didnt work. Please help!!! awk '{substr($0,5,1) ~ /|/}{print}' $input_file > $temp_file (1 Reply)
Discussion started by: gpaulose
1 Replies
Login or Register to Ask a Question