0

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?

2
  • Actually I wanted to obtain after that a modified filed, with the contant shown above. Thanks much
    – yyyzzz
    Oct 6, 2013 at 17:44
  • Sorry, I cannot understand. Perhaps you mean you want to modify the file inplace? Oct 6, 2013 at 17:46

3 Answers 3

2

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

3
  • ... you should consider what your class is about ...: +1. I though this was a pure-shell question, but I could be wrong. Oct 6, 2013 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, 2013 at 17:45
  • No, that is not homework :) I am getting used to Linux environment
    – yyyzzz
    Oct 6, 2013 at 17:47
1
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.

0
0

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

awk '{print $0,"\ntype your symbols here "}' input > output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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