I want to change a number in a file into number -1..
for instance
file_input is
fdisdlf_s35
fdjsk_s27
fsdf_s42
jkljllljkkl_s57
... etc
now i want the output to be
fdisdlf_s34
fdjsk_s26
fdsf_s41
jkljllljkkl_s56
... etc
I was think of using "sed -e 's/2/1/g' -e 's/3/2/g' -e 's/4/3/g' ...etc file_input>new_file"
but it changes each character and give me an output of
fdisdlf_s22
fdjsk_s14
fdsf_s29
jkljllljkkl_s44
how do i fix this
era
2
sed is not the right tool. Try awk or perl.
perl -ple 's/(\d+)$/$1 - 1/ge'
I'm new to this and would like to know what this is doing
era
4
s/// is the substitution command you are familiar with from sed.
The regular expression \d+ is just a shorthand for [0-9]+ and putting it in parentheses "captures" it so you can refer back to it.
In the substitution part, we actually put a little Perl script, which subtracts one from the value we captured earlier (now referred to as $1).
The /g option says do this globally (really not necessary here).
The /e option is special to Perl, and says execute the substitution part, rather than just treat it as text.
Hope this helps.
yes thank you very much
this worked perfect