Hi,
I have numerous files which have data in the following format
I want to remove decimal point only if it is last character in a number.
O/p should be
I tried this
Problem with above is that it removes the '.' for Mr.
Also I want to remove '.' for last field in second line 45. should be 45
Basically any numeric filed which has a decimal but no number after decimal, should have decimal point removed
Note that the suggestions test if the preceding character is a digit, not if a field that consists of a number ends with a dot. For example if one of the fields would be A1. then this approach would fail.
An alternative would be to split it into fields and test each field if it is numeric and if it ends in a dot. For example:
Note that the suggestions test if the preceding character is a digit, not if a field that consists of a number ends with a dot. For example if one of the fields would be A1. then this approach would fail.
True. Here is a sed-script covering this:
Note that i need a loop (instead of the "g" option) because i have to match the leading AND the trailing field separator.
Works almost. The colon needs to go in front of the start label, and, due to the |*, it will remove A1.'s dot as well. Removing the star from the pipe, it will not catch the line start. Right now, I can't see a solution...
---------- Post updated at 10:42 ---------- Previous update was at 10:39 ----------
Even with ERE, you need to run it twice, perhaps conditionally if the first hits, as you used both start and end field '|'. Otherwise, you miss the following adjacent fields on a line like: "123.|456."
You can add pipes to both ends for the substitute and then remove them:
I could have removed both added pipes with one substitute "s/^|\(.*\)|$/\1/" but these back references are a bit slower, in my experience, so I avoid them where possible.
Two passes can be avoided if a less careful pattern is sought, like "s/\([0-9]\).|/\1/", as it encompasses only one pipe. It mangles any non-numeric field with a trailing numer and dot, like "123|The field count of this line is 3.|xyz".
These 2 Users Gave Thanks to DGPickett For This Post:
Hi all,
I need to do scrip for printing starting and ending numbers along with count in given file.:wall:
Input: a.txt
10000030
10000029
10000028
10000027
10000026
10000024
10000023
10000021
10000018
10000018
10000017
10000016
10000015
10000014 (2 Replies)
Hi, I have multiple large files which consist of the below format:
I am trying to write an awk or sed script to remove all occurrences of the 00 record except the first and remove all of the 80 records except the last one.
Any help would be greatly appreciated. (10 Replies)
Hello,
I am working with a list that contains a large number of files listed by their absolute path. I am trying to determine a way to delete the file name at the end of each line, therefore leaving just the directory path. For example, I'd like to go from:
/home/something/file... (2 Replies)
I have a file that has some text that looks like this
Some Text
1. More text
2. Different text
Final Text
I would like the remove the lines of text that start with the numbers.
Some Text
Final Text
I have tried to use cat file.txt | grep -Ev 1. >... (9 Replies)
Hi,
I am trying to cleanup 7 or 10 digits numeric from the file. So for example :
Input :
3M Corporation
3M Inc. 888-356-8765
3M Inc. 356-8765
3M Inc. 3568765
3M Inc. 356-8765
3M 8883568765 Inc.
Output :
3M Corporation
3M Inc. - -
3M Inc. -
3M Inc.
3M Inc. - (8 Replies)
Hi all,
I have a bunch of files that are named like 12543, 467249877, etc all over some directories.These files are named only with numbers, they dont have any letters or special characters in their file names. Could you please help me out and give me some command/script to remove only those... (6 Replies)