Need to add last character if is it numeric

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
satishmca
Posts: 2
Joined: 20 Sep 2014 06:57

Need to add last character if is it numeric

#1 Post by satishmca » 20 Sep 2014 07:06

hi,

can anyone guide me
if the line, last character contains number then it should be appended with that line,if not the output should be same

can anyone provide using awk,sed.

input.txt:
satish 56788 /opt/product/BETA/lsmpp_install/bin/startBETAsmpp 2
satish 76899 /opt/product/BETA/lsmpp_install/bin/startBETAsmsc a

output should be:

satish 56788 /opt/product/BETA/lsmpp_install/bin/startBETAsmpp2
satish 76899 /opt/product/BETA/lsmpp_install/bin/startBETAsmsc a

thanks in advance

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need to add last character if is it numeric

#2 Post by Squashman » 20 Sep 2014 08:42

This is primarily a Windows based scripting language forum. Do not expect a solution with Unix based tools that have been ported to Windows. Looks like you are using Unix or Linux based on your folder paths.
Please give better example of your input and output. Currently it looks the same to me.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Need to add last character if is it numeric

#3 Post by foxidrive » 20 Sep 2014 13:37

The question is phrased awkwardly - the OP wants to remove a space if the last character is a numeral.

This works with the sample data:

Code: Select all

type "input.txt"|repl "(.*) ([0-9])$" "$1$2"

This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Need to add last character if is it numeric

#4 Post by Squashman » 20 Sep 2014 15:40

foxidrive wrote:The question is phrased awkwardly - the OP wants to remove a space if the last character is a numeral.

Glad you understood. Would have been a lot easier to say "remove the space before the number"!

satishmca
Posts: 2
Joined: 20 Sep 2014 06:57

Re: Need to add last character if is it numeric

#5 Post by satishmca » 23 Sep 2014 16:37

Yes thanks for the solution in DOS, i just had doubt in unix so posted
I knew few people here in this forum agermnan and ghostmachine who used to solve in dos and awk.

Post Reply