Remove character from a column in each line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove character from a column in each line
# 1  
Old 03-18-2014
Remove character from a column in each line

Hi,

I am a newbie to shell scripting (.sh). Please guide me on how to do the below issue.

My input file has below data.
I want to remove $ sysmbol from the fourth column of each line. (ie, between 4th and 5th pipe symbol)
Code:
ABC25160|51497|06/02/2010|$32,192.07|MARK|$100|A
ABC08053|95149|06/02/2010|$47,904.95|TIM|$100|A
ABC53615|28172|14/02/2010|$40,636.85|CHRIS|$100|A
ABC88924|45149|21/02/2010|$30,363.69|TOM|$100|A

Please help
Sreejith

Last edited by Franklin52; 03-18-2014 at 09:21 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 03-18-2014
The problem is there is not spacing between your | if you had a space you could use awk and sed. With that being said if the value you're wanting to change is $100 and is the same in the file then you can use tr command.

Last edited by deaconf19; 03-18-2014 at 09:15 AM..
# 3  
Old 03-18-2014
Something like this?
Code:
awk -F"|" 'sub(".",x,$4)' OFS="|" file

# 4  
Old 03-18-2014
Maybe try this:

Code:
jasonralph-> cat test_file.txt 
ABC25160|51497|06/02/2010|$32,192.07|MARK|$100|A
ABC08053|95149|06/02/2010|$47,904.95|TIM|$100|A
ABC53615|28172|14/02/2010|$40,636.85|CHRIS|$100|A
ABC88924|45149|21/02/2010|$30,363.69|TOM|$100|A


Code:
jasonralph-> awk -F\| '{ sub(/^\$/, "", $4); print}' OFS="|" test_file.txt 
ABC25160|51497|06/02/2010|32,192.07|MARK|$100|A
ABC08053|95149|06/02/2010|47,904.95|TIM|$100|A
ABC53615|28172|14/02/2010|40,636.85|CHRIS|$100|A
ABC88924|45149|21/02/2010|30,363.69|TOM|$100|A

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 newline character from column spread over multiple lines in a file

Hi, I came across one issue recently where output from one of the columns of the table from where i am creating input file has newline characters hence, record in the file is spread over multiple lines. Fields in the file are separated by pipe (|) delimiter. As header will never have newline... (4 Replies)
Discussion started by: Prathmesh
4 Replies

2. UNIX for Dummies Questions & Answers

How to remove $ or new line character in a file?

Hi All, Could any one suggest how to remove $ symbol in a text file when i am opening in vi editor. Scenario; For example iam having a file name aaa.txt the data inside the file is like sample name when i am opening in vi editor The same file resembles like below when i am... (1 Reply)
Discussion started by: Chandru_Raj
1 Replies

3. Shell Programming and Scripting

Remove the first character from the fourth column only if the column has four characters

I have a file as follows ATOM 5181 N AMET K 406 12.440 6.552 25.691 0.50 7.37 N ATOM 5182 CA AMET K 406 13.685 5.798 25.578 0.50 5.87 C ATOM 5183 C AMET K 406 14.045 5.179 26.909 0.50 5.07 C ATOM 5184 O MET K... (14 Replies)
Discussion started by: hasanabdulla
14 Replies

4. UNIX for Dummies Questions & Answers

Remove last character in each line

Hi guys, Does anyone know how to remove the last character in each of the line? This is what I have: ABCDE.1 GLSJD.2 HIJPL.2 HKAGB.3 IUBWQ.1 What I want (remove the dot and number): ABCDE GLSJD HIJPL HKAGB IUBWQ I tried to use this: sed 's/.*//' But I'm not sure if that is... (3 Replies)
Discussion started by: narachaid
3 Replies

5. Shell Programming and Scripting

How to remove , if first character on line

Hi, I have a file with lines such as the below. I want to remove the comma only if it is the first character on a line. I can't work out how to do this using sed. *ELSET, ELSET=WHEEL_TD2 63, 64, 65, 72, 82, 88, 89, 92, 120, 121, 152, 181, 190, 221, 252, 259 , 260, 282, 283, 285, 286,... (2 Replies)
Discussion started by: carlr
2 Replies

6. Shell Programming and Scripting

remove special character from a specific column

Hello , i have a text file like this : A123 c12AB c32DD aaaa B123 23DS 12QW bbbb C123 2GR 3RG cccccc i want to remove the numbers from second and third column only. i tried this : perl -pe 's///g' file.txt > newfile.txt but it will remove the number from... (7 Replies)
Discussion started by: shelladdict
7 Replies

7. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

8. UNIX for Advanced & Expert Users

To remove new line character

Hi, I am facing one interesting problem : I have a file which contains data like this 459,|1998-11-047|a |b |c \n efg | d|e | \n 459,|1998-11-047|a \n c|b |c \n efg | d|e | \n Basically what I have to do is , I have to remove all \n which is coming ( enclosed ) in between... (7 Replies)
Discussion started by: shihabvk
7 Replies

9. UNIX for Dummies Questions & Answers

Trying to remove single character from a line

Here is a sample code grep '903' -i user.txt | tail -2 | awk '{print $2}' | sed 's/B//g' the input file has data as such 903-xxx-xxxxB 903-xxx-xxxxB It is a dialer file i want to remove the "B" any help thanks (5 Replies)
Discussion started by: Iz3k34l
5 Replies

10. Shell Programming and Scripting

Remove Last Character of Line

Hi, I need to put the single line contents of a file into a variable, but remove the last character, for example the file would have this sort of contents: 2;4;3;10;67;54;96; And I want the variable to be: 2;4;3;10;67;54;96 (notice the last ";" has gone). Unfortunately I can't just... (4 Replies)
Discussion started by: danhodges99
4 Replies
Login or Register to Ask a Question