Visit Our UNIX and Linux User Community


perl - Removing dots(".") from the data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl - Removing dots(".") from the data
# 1  
Old 12-12-2012
Question perl - Removing dots(".") from the data

Hi Friends,


I have a file1 as below

file1.txt

Code:
 
100000.||1925-01-10|00:00|1862SHERMA NAVE#1SE.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670
100001.||1935-01-10|00:00|1862NEW . YRK NO.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670.
100002.||1965-01-10|00:00|1862 IND . INC,CL .NAVE#1SE.||EVTON|IL|60201||22.509.|BDSS|62007.|2.639.|26670

I am using the below command to remove the dots"." from the file where before "|'


Code:
 
#perl -pe 's/\.(?=[|\s])//g' file1.txt
 
100000||1925-01-10|00:00|1862SHERMA NAVE#1SE||EVTON|IL|60201||22509|BDSS|62007|2639|26670
100001||1935-01-10|00:00|1862NEW  YRK NO||EVTON|IL|60201||22509|BDSS|62007|2639|26670
100002||1965-01-10|00:00|1862 IND  INC,CL .NAVE#1SE||EVTON|IL|60201||22.509|BDSS|62007|2.639.|26670


The output will remove all the dots for the interger fields and also the Address field which is mentioned as green .But i want to remove the dots only when column field is Integer and want to remove dot"." only before "|"

Expected output:

Code:
 
100000||1925-01-10|00:00|1862SHERMA NAVE#1SE.||EVTON|IL|60201||22509|BDSS|62007|2639|26670
100001||1935-01-10|00:00|1862NEW . YRK NO.||EVTON|IL|60201||22509|BDSS|62007|2639|26670
100002||1965-01-10|00:00|1862 IND . INC,CL .NAVE#1SE.||EVTON|IL|60201||22.509|BDSS|62007|2.639.|26670

Plz help

Last edited by i150371485; 12-12-2012 at 09:31 AM..
# 2  
Old 12-12-2012
Try

Code:
perl -pe 's/\.\|/\|/g' file
100000||1925-01-10|00:00|1862SHERMA NAVE#1SE||EVTON|IL|60201||22509|BDSS|62007|2639|26670
100001||1935-01-10|00:00|1862NEW . YRK NO||EVTON|IL|60201||22509|BDSS|62007|2639|26670.
100002||1965-01-10|00:00|1862 IND . INC,CL .NAVE#1SE||EVTON|IL|60201||22.509|BDSS|62007|2.639|26670

This User Gave Thanks to pamu For This Post:
# 3  
Old 12-12-2012
@Pamu Thanks for the quick response . Again in the 5th field the dot is removing. I actually dont want to remove the "dots"(.) from text fields . I should only remove the "." from the Number fields .

Expected Output :

Code:
 
100000||1925-01-10|00:00|1862SHERMA NAVE#1SE.||EVTON|IL|60201||22509|BDSS|62007|2639|26670
100001||1935-01-10|00:00|1862NEW . YRK NO.||EVTON|IL|60201||22509|BDSS|62007|2639|26670
100002||1965-01-10|00:00|1862 IND . INC,CL .NAVE#1SE.||EVTON|IL|60201||22.509|BDSS|62007|2.639.|26670


Last edited by i150371485; 12-12-2012 at 09:31 AM..
# 4  
Old 12-12-2012
See if this works:
Code:
perl -pe 's/(^|(?<=\|))([0-9.]+)\.(\||$)/$2$3/g' file

These 2 Users Gave Thanks to Scrutinizer For This Post:
# 5  
Old 12-12-2012
@Scrutinizer : Thanks for the reply. it works as expected. Thank you Smilie . Would you mind explaning the command ?
# 6  
Old 12-12-2012
Hi, if there is a match that involves:
group 1: the beginning of a line(^) or a field separator (\|), followed by
group 2: 1 or more numbers or dots, followed by
a dot(\.), followed by
group 3: a field separator (\|) or the end of a line ($).

Then replace that by the reference to group 2 and 3.
group 1 contains a lookbehind to the previous field separator ((?<=\|)), so that it is not part of the actual match. This is important, otherwise not every field would be matched, because the regex would start looking for a next match, where the previous match ended..
This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 12-13-2012
@Scrutinizer : Thank you so much Smilie

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Perl scripting to get "Wanted Data"

I have data like below : Source file : input.txt ( so many data with same format ) 09.05.2014 09.49.52:359 RID:routerNode1@app1:1662306081,msisdn:787887225696,sid:93889095007001,tid:1405090902095648846024000,status:2,time:20140509094952,reason:DELIVRD,refund:null,status2:null ... (6 Replies)
Discussion started by: MacLing66
6 Replies

4. Shell Programming and Scripting

Awk-sed - wc : how to count DOTS "."'s in a file.

Hi Experts , file: EST 2013::.................................................................................................................................................................................................................................................cmihx021:/home/data1/ ... (11 Replies)
Discussion started by: rveri
11 Replies

5. Shell Programming and Scripting

Removing "^M" from the end of a String (i.e. "Ctrl+M")?

Hello All, I have an Expect script that ssh's to a remote server and runs some commands before exiting. One of the commands I run is the "hostname" Command. After I run this command I save the output using this line in the code below... Basically it executes the hostname command, then I... (2 Replies)
Discussion started by: mrm5102
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

show dots when script is "thinking"

Hey, I'm running the following script: #!/bin/bash kjv=kjv.txt trim(){ local trim_string local _TRIM=$1 trim_string=${_TRIM##*} _TRIM=${_TRIM#"trim_string"} echo $_TRIM } #trim() { # echo $( _trim "$@" ) #} printf "How many chapters? " read response (10 Replies)
Discussion started by: pkohn11
10 Replies

8. Shell Programming and Scripting

removing the "\" and "\n" character using sed or tr

Hi All, I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example... this is a test line #1\ should be concatenated with line #2\ and line number 3 when this... (3 Replies)
Discussion started by: newbie_coder
3 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

Featured Tech Videos