Using sed command to change each letter to the next one in the alphabet
Here is what is the file beast.txt: savage beast tank beauty
I am looking to get it to look like: tbwbhf cfbtu ubol cfbvuz
This what I have but when I run this it changes the letters to "[a-z]+1".
cat beast.txt | sed 's/[a-z]/[a-z]+1/g' > savage.txt
Do I have to use other special characters to in the sed command or should this be done with a loop? Thank you for your help.
2 answers
-
answered 2021-02-22 22:31
William Pursell
This is not a job for sed:
$ echo 'savage beast tank beauty' | tr a-z b-za tbwbhf cfbtu ubol cfbvuz
If you really want to use sed, you can do:
$ b2z=bcdefghijklmnopqrstuvwxyz $ echo 'savage beast tank beauty' | sed -e "y/a$b2z/${b2z}a/" tbwbhf cfbtu ubol cfbvuz
-
answered 2021-02-22 23:44
bildungsroman11
I used this '$ echo 'savage beast tank beauty' | tr a-z b-za' and it worked.
I am now having trouble reversing what I just did.
See also questions close to this topic
-
how to bulk add categories and subcategories structure
I'd like to bulk create categories and subcategories in my wordpress site.
I have this file with categories and subcategories levels. How to add this categories hierarchy with wp-cli in bash ? Something like this, but for the whole structure
idlevel1=$(wp term create category name-of-level-1 --porcelain) wp term create category name-level-2_1 --parent=$idlevel1 wp term create category name-level-2_2 --parent=$idlevel1 wp term create category name-level-2_3 --parent=$idlevel1 wp term create category name-level-2_3 --parent=$idlevel1
Thanks
Name BG color category level ALSACE #ffff00 1 GROUPEMENT DU BAS-RHIN #d8d8d8 2 BERNARDSWILLER #ffffff 3 BISCHOFFSHEIM #ffffff 3 EBERSHEIM #ffffff 3 HOCHFELDEN #ffffff 3 MEISTRATZHEIM #ffffff 3 NIEDERNAI #ffffff 3 OBERNAI #ffffff 3 OTTROTT #ffffff 3 SCHIRMECK #ffffff 3 Vallée de la Bruche #ffffff 3 STRASBOURG #ffffff 3 AQUITAINE #ffff00 1 DAX #ffffff 3 SOUSTONS #ffffff 3 BRETAGNE #ffff00 1 GROUPEMENT DU FINISTERE #d8d8d8 2 GROUPEMENT LOIRE-ATLANTIQUE #d8d8d8 2 GROUPEMENT DU MORBIHAN #d8d8d8 2 SECTEUR DE BROCELIANDE #d8d8d8 2 CARO #ffffff 3 RUFFIAC #ffffff 3 St MARCEL #ffffff 3 SECTEUR DU PAYS GALLO #d8d8d8 2 BILLIO #ffffff 3 BULEON #ffffff 3 COLPO #ffffff 3 ELVEN #ffffff 3 GUEHENNO #ffffff 3 LOCMARIA GRAND CHAMP #ffffff 3 LOQUELTAS #ffffff 3 MOHON #ffffff 3 MONTERBLANC #ffffff 3 CONTACT COURRIER TELEPHONE - MONTERBLANC #ffffff 3 PLAUDREN #ffffff 3 PLUMELEC #ffffff 3 SAINT-ALLOUESTRE #ffffff 3 SAINT-JEAN BREVELAY #ffffff 3 SECTEUR DE LANVAUX #d8d8d8 2 BRANDIVY #ffffff 3 CAMORS #ffffff 3 double du courrier de M. LE TUTOUR #ffffff 3 GRAND CHAMP #ffffff 3 PLUMERGAT #ffffff 3 PLUVIGNER #ffffff 3 PLUMELIN #ffffff 3 QUISTINIC #ffffff 3 SECTEUR DU PAYS D'AURAY #d8d8d8 2 PLUNERET #ffffff 3 AURAY #ffffff 3
-
Error trying to compile C file: mkfifo: cannot create fifo 'stderr': Operation not supported
We are trying to compile this by following instructions in the readme. I must say that we are not specialists with C at all, we are students of a web development bootcamp and trying to do our last project.
It's a command line tool to calculate ephemerides of multiple celestial bodies, and as you can read in the setup in the readme file, it need to download certain data from the internet, and then compile. All is done through the
setup.sh
script.So, we have tried:
- In Windows 10 ubuntu WSL terminal
If we type
$./setup
or$./prettymake
, after download the data, gives the error:$mkfifo: cannot create fifo 'stderr': Operation not supported $mkdir -p obj obj/argparse obj/coreUtils obj/ephemCalc obj/listTools obj/mathsTools obj/settings cc -Wall -Wno-format-truncation -Wno-unknown-pragmas -g -c -I /mnt/d/reboot/ephemeris-compute-de430/src -O3 -D DEBUG=0 -D MEMDEBUG1=0 -D MEMDEBUG2=0 -fopenmp -D DCFVERSION=\"2.0\" -D DATE=\"09/06/2019\" -D PATHLINK=\"/\" -D SRCDIR=\"/mnt/d/reboot/ephemeris-compute-de430/src/\" src/ephemCalc/constellations.c -o obj/ephemCalc/constellations.o
If we do it with
$sudo ./setup
, the error printed is:$mkfifo: cannot create fifo 'stderr': Operation not supported $cat: stderr: No such file or directory $mkdir -p obj obj/argparse obj/coreUtils obj/ephemCalc obj/listTools obj/mathsTools obj/settings cc -Wall -Wno-format-truncation -Wno-unknown-pragmas -g -c -I /mnt/d/reboot/ephemeris-compute-de430/src -O3 -D DEBUG=0 -D MEMDEBUG1=0 -D MEMDEBUG2=0 -fopenmp -D DCFVERSION=\"2.0\" -D DATE=\"09/06/2019\" -D PATHLINK=\"/\" -D SRCDIR=\"/mnt/d/reboot/ephemeris-compute-de430/src/\" src/ephemCalc/constellations.c -o obj/ephemCalc/constellations.o
- In macOS terminal
If we type
$./prettymake
, gives the error:$mkdir -p obj obj/argparse obj/coreUtils obj/ephemCalc obj/listTools obj/mathsTools obj/settings cc -Wall -Wno-format-truncation -Wno-unknown-pragmas -g -c -I /Users/rominaelorrietalopez/Documents/Descargas2/ephemeris-compute-de430-master/src -O3 -D DEBUG=0 -D MEMDEBUG1=0 -D MEMDEBUG2=0 -fopenmp -D DCFVERSION=\"2.0\" -D DATE=\"09/06/2019\" -D PATHLINK=\"/\" -D SRCDIR=\"/Users/rominaelorrietalopez/Documents/Descargas2/ephemeris-compute-de430-master/src/\" src/argparse/argparse.c -o obj/argparse/argparse.o $clang: error: unsupported option '-fopenmp' $make: *** [obj/argparse/argparse.o] Error 1
We have tried certain things to no avail, like granting permissions and what not, but have no idea what to do next.
It seems that it have something to do with the prettymake file:
mkfifo stderr cat stderr | sed 's/\(.*\)/\1/' & make $@ 2>stderr | sed 's/\(.*\)/\1/' rm stderr
It's like its trying to create a pipe to save the errors of the compilation but somehow it fails. Also possibly worth of mention, it have a Makefile associated.
Since the github project does not have Issues, we've contacted the creator via email, but well, we thought maybe someone could help us here too.
Any kind of help would be honestly appreciated, thanks.
-
$BASH_COMMAND is overwritten too early in Trap DEBUG
I have
trap 'python my_script.py --command \"$BASH_COMMAND\"' DEBUG
my_script.py is
from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument('--command', default="") args = parser.parse_args() command = args.command print("COMMAND", command)
But when I run a bash command the output is
PROMPT_COMMAND='python my_script.py'
Rather than the command that was run that triggered the trap.
How can I get the initial run command from my_script.py?
-
Extract all rows which contain <20 exons in a transcript
The first 3 column contains the genome coordinates 4th column contains transcript name 5th column contains exon name and 6th column contain exon rank. So I want to separate this file into 2 files: 1st files if the transcript contains a total <20 exons then print all exons and another file in which if the transcript contains a total of more than 20 exons then print all exons in a different file.
X 70444861 70445558 ENST00000194900 ENSE00001463308 1 X 70448580 70448633 ENST00000194900 ENSE00001463307 2 X 70448913 70448963 ENST00000194900 ENSE00003643927 3 X 70449359 70449483 ENST00000194900 ENSE00003548284 4 X 70449690 70449859 ENST00000194900 ENSE00003690291 5 X 70450169 70450305 ENST00000194900 ENSE00000436378 6 X 70450639 70450783 ENST00000194900 ENSE00000672250 7 X 70451867 70452026 ENST00000194900 ENSE00003562095 8 X 70453637 70453793 ENST00000194900 ENSE00003664498 9 X 70454214 70454316 ENST00000194900 ENSE00003617252 10 X 70479150 70479264 ENST00000194900 ENSE00003589163 11 X 70492107 70492283 ENST00000194900 ENSE00003626140 12 X 70492521 70492596 ENST00000194900 ENSE00003469450 13 X 70495408 70495453 ENST00000194900 ENSE00003692914 14 X 70497180 70497221 ENST00000194900 ENSE00003595614 15 X 70498520 70498570 ENST00000194900 ENSE00003511316 16 X 70499176 70499277 ENST00000194900 ENSE00003615707 17 X 70499877 70500049 ENST00000194900 ENSE00003483338 18 X 70500471 70500580 ENST00000194900 ENSE00003686632 19 X 70500898 70500989 ENST00000194900 ENSE00003626326 20 X 70502163 70505490 ENST00000194900 ENSE00003733449 21 X 120426148 120431462 ENST00000200639 ENSE00001187748 9 X 120441730 120441894 ENST00000200639 ENSE00000854520 8 X 120442599 120442662 ENST00000200639 ENSE00000374515 7 X 120446305 120446427 ENST00000200639 ENSE00000854522 6 X 120447841 120448025 ENST00000200639 ENSE00000854523 5 X 120448970 120449128 ENST00000200639 ENSE00000854524 4 X 120455357 120455570 ENST00000200639 ENSE00000675764 3 X 120456651 120456769 ENST00000200639 ENSE00003615412 2 X 120469106 120469296 ENST00000200639 ENSE00003896841 1 X 68829021 68829904 ENST00000204961 ENSE00001041113 1 X 68838617 68838894 ENST00000204961 ENSE00000672435 2 X 68839664 68839756 ENST00000204961 ENSE00000672436 3 X 68839960 68840088 ENST00000204961 ENSE00000672437 4 X 68840242 68842160 ENST00000204961 ENSE00001041114 5 X 100843836 100844078 ENST00000217885 ENSE00001857295 12 X 100848630 100848754 ENST00000217885 ENSE00000401023 11 X 100849772 100849934 ENST00000217885 ENSE00000401021 10 X 100850151 100850386 ENST00000217885 ENSE00001661840 9 X 100851233 100851325 ENST00000217885 ENSE00001607924 8 X 100862171 100862303 ENST00000217885 ENSE00001702593 7 X 100862392 100862573 ENST00000217885 ENSE00001701549 6 X 100862669 100862820 ENST00000217885 ENSE00001637130 5 X 100863159 100863243 ENST00000217885 ENSE00001653972 4 X 100863485 100863595 ENST00000217885 ENSE00001767233 3 X 100870719 100870814 ENST00000217885 ENSE00001602753 2 X 100874095 100874209 ENST00000217885 ENSE00001187812 1 X 2913614 2914773 ENST00000217890 ENSE00001203379 7 X 2915556 2915692 ENST00000217890 ENSE00003684272 6 X 2917804 2918227 ENST00000217890 ENSE00003509340 5 X 2920601 2920723 ENST00000217890 ENSE00003691518 4 X 2921903 2922024 ENST00000217890 ENSE00003652714 3 X 2925616 2925765 ENST00000217890 ENSE00003691123 2 X 2929232 2929275 ENST00000217890 ENSE00001881224 1
After the output, the 2 files looks like this:- The first files look like:-
X 120426148 120431462 ENST00000200639 ENSE00001187748 9 X 120441730 120441894 ENST00000200639 ENSE00000854520 8 X 120442599 120442662 ENST00000200639 ENSE00000374515 7 X 120446305 120446427 ENST00000200639 ENSE00000854522 6 X 120447841 120448025 ENST00000200639 ENSE00000854523 5 X 120448970 120449128 ENST00000200639 ENSE00000854524 4 X 120455357 120455570 ENST00000200639 ENSE00000675764 3 X 120456651 120456769 ENST00000200639 ENSE00003615412 2 X 120469106 120469296 ENST00000200639 ENSE00003896841 1 X 68829021 68829904 ENST00000204961 ENSE00001041113 1 X 68838617 68838894 ENST00000204961 ENSE00000672435 2 X 68839664 68839756 ENST00000204961 ENSE00000672436 3 X 68839960 68840088 ENST00000204961 ENSE00000672437 4 X 68840242 68842160 ENST00000204961 ENSE00001041114 5 X 100843836 100844078 ENST00000217885 ENSE00001857295 12 X 100848630 100848754 ENST00000217885 ENSE00000401023 11 X 100849772 100849934 ENST00000217885 ENSE00000401021 10 X 100850151 100850386 ENST00000217885 ENSE00001661840 9 X 100851233 100851325 ENST00000217885 ENSE00001607924 8 X 100862171 100862303 ENST00000217885 ENSE00001702593 7 X 100862392 100862573 ENST00000217885 ENSE00001701549 6 X 100862669 100862820 ENST00000217885 ENSE00001637130 5 X 100863159 100863243 ENST00000217885 ENSE00001653972 4 X 100863485 100863595 ENST00000217885 ENSE00001767233 3 X 100870719 100870814 ENST00000217885 ENSE00001602753 2 X 100874095 100874209 ENST00000217885 ENSE00001187812 1 X 2913614 2914773 ENST00000217890 ENSE00001203379 7 X 2915556 2915692 ENST00000217890 ENSE00003684272 6 X 2917804 2918227 ENST00000217890 ENSE00003509340 5 X 2920601 2920723 ENST00000217890 ENSE00003691518 4 X 2921903 2922024 ENST00000217890 ENSE00003652714 3 X 2925616 2925765 ENST00000217890 ENSE00003691123 2 X 2929232 2929275 ENST00000217890 ENSE00001881224 1
The second files look like this:-
X 70444861 70445558 ENST00000194900 ENSE00001463308 1 X 70448580 70448633 ENST00000194900 ENSE00001463307 2 X 70448913 70448963 ENST00000194900 ENSE00003643927 3 X 70449359 70449483 ENST00000194900 ENSE00003548284 4 X 70449690 70449859 ENST00000194900 ENSE00003690291 5 X 70450169 70450305 ENST00000194900 ENSE00000436378 6 X 70450639 70450783 ENST00000194900 ENSE00000672250 7 X 70451867 70452026 ENST00000194900 ENSE00003562095 8 X 70453637 70453793 ENST00000194900 ENSE00003664498 9 X 70454214 70454316 ENST00000194900 ENSE00003617252 10 X 70479150 70479264 ENST00000194900 ENSE00003589163 11 X 70492107 70492283 ENST00000194900 ENSE00003626140 12 X 70492521 70492596 ENST00000194900 ENSE00003469450 13 X 70495408 70495453 ENST00000194900 ENSE00003692914 14 X 70497180 70497221 ENST00000194900 ENSE00003595614 15 X 70498520 70498570 ENST00000194900 ENSE00003511316 16 X 70499176 70499277 ENST00000194900 ENSE00003615707 17 X 70499877 70500049 ENST00000194900 ENSE00003483338 18 X 70500471 70500580 ENST00000194900 ENSE00003686632 19 X 70500898 70500989 ENST00000194900 ENSE00003626326 20 X 70502163 70505490 ENST00000194900 ENSE00003733449 21
So please can anyone tell me how to make 2 files. Thanks in advance.
-
SED replace in file
I'm trying to do a simple (I think) search and replace in a file.
Search for the test wrapped between
@{...}
and replace it with%<...>
.For example:
@{SOMETEXT_A}
becomes$<SOMETEXT_A>
@{SOMETEXT_B}
becomes$<SOMETEXT_B>
@{SOMETEXT_C}
becomes$<SOMETEXT_C>
I have this in sed which matches the search params,
sed -i 's/\@{.\*}/\$<.\*>/g' input.txt
..but doesn't copy the string to the result and instead results in
$<.*>
How do I copy over the regex match from ".*" into the replace string?
Many thanks
-
How to replace string in a specific line using sed command or awk
I have a text file and it has the following contents
# # Keywords: # LiFePO4 end name Li5FeO4 cell 18.557309 18.316802 9.125725 90.047539 90.100646 90.060551 0 0 0 0 0 0 fractional 1 Li core 0.06001 0.059408 0.849507 1 1 0 0 0 0 Li1 core 0.025416 0.339078 0.128746 1 1 0 0 0 0 Li2 core 0.02517 0.838929 0.130747 1 1 0 0 0 0 Li3 core 0.525498 0.339179 0.127632 1 1 0 0 0 0 Li4 core 0.524753 0.841333 0.129329 1 1 0 0 0 0 Li5 core 0.179907 0.158182 0.634012 1 1 0 0 0 0 Li6 core 0.180817 0.666028 0.628327 1 1 0 0 0 0
This is the input that I need to supply to a tool which used in some research application. Now I need to replace the
0
on the first line which starts withLi
on the third column from the last. That is, there are four zeros towards the end in each of the lines starting withLi
. I need to replace the second zero and so the file will have the the contents as follows:# # Keywords: # LiFePO4 end name Li5FeO4 cell 18.557309 18.316802 9.125725 90.047539 90.100646 90.060551 0 0 0 0 0 0 fractional 1 Li core 0.06001 0.059408 0.849507 1 1 0 1 0 0 Li1 core 0.025416 0.339078 0.128746 1 1 0 0 0 0 Li2 core 0.02517 0.838929 0.130747 1 1 0 0 0 0 Li3 core 0.525498 0.339179 0.127632 1 1 0 0 0 0 Li4 core 0.524753 0.841333 0.129329 1 1 0 0 0 0 Li5 core 0.179907 0.158182 0.634012 1 1 0 0 0 0 Li6 core 0.180817 0.666028 0.628327 1 1 0 0 0 0
I am planning to use this in a shell script so that I can supply the modified file as an input to another program and use it's out put for further processing.
I have tried the following code, but it is not working
sed -E "s/^(([^ ]+ +){3})0 /\1 /" file1