Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to create a script that insert 20 characters following each line in a text file.

Suppose the file contains the following lines:

text....
text....
text...

I want to obtain:

text....
------(20 symbols)
text....
------(20 symbols)
text...
------(20 symbols)

How to do this?

share|improve this question
    
Actually I wanted to obtain after that a modified filed, with the contant shown above. Thanks much –  yyyzzz Oct 6 '13 at 17:44
    
Sorry, I cannot understand. Perhaps you mean you want to modify the file inplace? –  Andrea Corbellini Oct 6 '13 at 17:46
add comment

3 Answers 3

up vote 1 down vote accepted
while read line
do
    echo "$line"
    echo "characters"
done < input > output

Where input is the source file and output is the destination file.

If you want to input and output to be the standard input and output respectively, then replace done < input > output with just done.

share|improve this answer
    
Thank you much!!!! –  yyyzzz Oct 6 '13 at 17:53
add comment

One way (there are many) is using the sed append command

sed 'a\
Extra twenty characters
' myfile

If this is for homework, you should consider what your class is about and what you are supposed to be learning, and select the most appropriate answer based on that

share|improve this answer
    
... you should consider what your class is about ...: +1. I though this was a pure-shell question, but I could be wrong. –  Andrea Corbellini Oct 6 '13 at 17:44
    
Thank you! Can you please tell me how this will apend text after each line of text file? Thanks much in advance! –  yyyzzz Oct 6 '13 at 17:45
    
No, that is not homework :) I am getting used to Linux environment –  yyyzzz Oct 6 '13 at 17:47
add comment

If input file is Hugh then you could use awk to perform it faster..

awk '{print $0,"\ntype your symbols here "}' input > output
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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