How to replace and edit content of file?

Mendel

I have a file which contains the following content:

set0027:
set0027_100-250
set0027_1-150
set0027_50-200

set0038:
set0038_100-250
set0038_1-150
set0038_50-200

I want to modify it in the following way:

cd set0027
clustalw INFILE=set0027_100-250 OUTFILE=set0027_100-250.aln
clustalw INFILE=set0027_1-150 OUTFILE=set0027_1-150.aln
clustalw INFILE=set0027_50-200 OUTFILE=set0027_50-200.aln
cd ..
cd set0038
clustalw INFILE=set0038_100-250 OUTFILE=set0038_100-250.aln
clustalw INFILE=set0038_1-150 OUTFILE=set0038_1-150.aln
clustalw INFILE=set0038_50-200 OUTFILE=set0038_50-200.aln
cd ..

How can I do this using bash script?

Essex Boy

Something like this will work:

$ perl -npe 's/(.*):/cd \1/; s/^(set.*)/clustalw INFILE=\1 OUTFILE=\1.aln/; s/^\s+/cd ..\n/;' file
cd set0027
clustalw INFILE=set0027_100-250 OUTFILE=set0027_100-250.aln
clustalw INFILE=set0027_1-150 OUTFILE=set0027_1-150.aln
clustalw INFILE=set0027_50-200 OUTFILE=set0027_50-200.aln
cd ..
cd set0038
clustalw INFILE=set0038_100-250 OUTFILE=set0038_100-250.aln
clustalw INFILE=set0038_1-150 OUTFILE=set0038_1-150.aln
clustalw INFILE=set0038_50-200 OUTFILE=set0038_50-200.aln

uses command line options

-n implicit loop
-e execute perl inline
-p print line

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to edit the file content in vi?

From Dev

How to edit .vimrc file to replace tab with spaces?

From Dev

How can I edit the content of a ini file?

From Dev

How can I edit the content of .properties file?

From Dev

How to edit content of a tag in a xml file

From Dev

How to edit/replace single file in SFDC static resources?

From Dev

how to replace some specific content of a file with the first line of another file?

From Dev

Replace a string by the content of a file

From Dev

How to replace a particular field in a file based on the content of another field?

From Dev

How to replace the content of specific column with awk? Tab Delimited File

From Dev

How to replace a particular field in a file based on the content of another field?

From Dev

How to replace some specific content (of various lines) of a file with the command sed?

From Dev

How to edit page content in Drupal

From Dev

How can I get file content between two HTML comments and replace it with content from another file?

From Dev

How to edit the GRUB file

From Dev

How to edit gitignore file

From Dev

How to edit the GRUB file

From Dev

How to edit a file with ed?

From Dev

How to edit a .sx file

From Dev

Replace string with multiline file content

From Dev

Replace string with multiline file content

From Dev

Replace content inte a PDF File

From Dev

sed: replace range with file content

From Dev

Replace content in file using bash

From Dev

jquery replace div content with jsp file content

From Dev

Edit strings.xml file content in Android

From Dev

Edit content of JSON file imported to MongoDB

From Dev

Inno Setup Compiler: How to edit INI file and replace a value with {app} constant

From Dev

How to import the entire content of a text file into Edit Text Box of Matlab GUI?

Related Related

  1. 1

    How to edit the file content in vi?

  2. 2

    How to edit .vimrc file to replace tab with spaces?

  3. 3

    How can I edit the content of a ini file?

  4. 4

    How can I edit the content of .properties file?

  5. 5

    How to edit content of a tag in a xml file

  6. 6

    How to edit/replace single file in SFDC static resources?

  7. 7

    how to replace some specific content of a file with the first line of another file?

  8. 8

    Replace a string by the content of a file

  9. 9

    How to replace a particular field in a file based on the content of another field?

  10. 10

    How to replace the content of specific column with awk? Tab Delimited File

  11. 11

    How to replace a particular field in a file based on the content of another field?

  12. 12

    How to replace some specific content (of various lines) of a file with the command sed?

  13. 13

    How to edit page content in Drupal

  14. 14

    How can I get file content between two HTML comments and replace it with content from another file?

  15. 15

    How to edit the GRUB file

  16. 16

    How to edit gitignore file

  17. 17

    How to edit the GRUB file

  18. 18

    How to edit a file with ed?

  19. 19

    How to edit a .sx file

  20. 20

    Replace string with multiline file content

  21. 21

    Replace string with multiline file content

  22. 22

    Replace content inte a PDF File

  23. 23

    sed: replace range with file content

  24. 24

    Replace content in file using bash

  25. 25

    jquery replace div content with jsp file content

  26. 26

    Edit strings.xml file content in Android

  27. 27

    Edit content of JSON file imported to MongoDB

  28. 28

    Inno Setup Compiler: How to edit INI file and replace a value with {app} constant

  29. 29

    How to import the entire content of a text file into Edit Text Box of Matlab GUI?

HotTag

Archive