-3

I am trying to create a script to add an indent to a file. So I put this in my file called ind--

sed 's/^./\t&/'  $*

When I run it my command is ind lines and it is supposed to open file lines and print it with an indent. Instead it gives an error no command ind found did i mean and then it gives 15 suggestions and then last line reads ind command not found. I am using putty and I just run it ind lines. I created script in vi

a. Can someone point out what is wrong and why it won't indent please??

closed as unclear what you're asking by jasonwryan, cuonglm, Archemar, Sparhawk, dr01 Nov 8 '15 at 12:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please edit your question and add the full error message you are having..also how did you run the script? – heemayl Nov 8 '15 at 2:38
1
#! /bin/sh
sed -e 's/^/\t/' "$@"

No need for the . or the & in the search or replace part.

Save as ./ind and make executable with chmod +x ./ind. run as ./ind lines. optionally mv ./ind to somewhere in your $PATH so you can run it from anywhere. (e.g. add ~/bin to your PATH and mv ./ind ~/bin/

  • glad to hear it. btw, this is such a simple example of sed usage that i wouldnt even bother putting it in its own script file. but its a good example for more complicated sed/bash/awk/perl etc scripts. also btw, if the file you are indenting is C, C++, java, etc source code you may want to look at the indent or astyle programs. – cas Nov 8 '15 at 2:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.