Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've a file with the following text:

<RecordID>02.037.D00221700080.0</RecordID>
2.35
AB
<RecordID>02.037.D00221700080.1</RecordID>
2.45
BB
<RecordID>02.037.D00221700080.2</RecordID>
6.5
CC

I wish to remove the dots, between <RecordID> and </RecordID> to get this:

<RecordID>02037D002217000800</RecordID>
2.35
AB
<RecordID>02037D002217000801</RecordID>
2.45
BB
<RecordID>02037D002217000802</RecordID>
6.5
CC

I've tried different approaches with sed, all of them without results... Thanks in advance!

question from:https://stackoverflow.com/questions/65943112/how-to-use-sed-to-remove-dots-between-2-patterns

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
192 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use this Perl one-liner:

perl -pe '/RecordID/ and tr/.//d;' in_file

The Perl one-liner uses these command line flags:
-e : Tells Perl to look for code in-line, instead of in a file.
-p : Loop over the input one line at a time, assigning it to $_ by default. Add print $_ after each loop iteration.

SEE ALSO:
perldoc perlrun: how to execute the Perl interpreter: command line switches
perldoc perlrequick: Perl regular expressions quick start


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...