1

I have to scan the no of characters in a file and to write to that file itself with a hardcoded way like 99|EOF|. for eg: if a text file : test.txt is having abcd as text in it. count will be 4. So i need to write a next line in same file ie: test.txt like 99|EOF|4 Can anyone help me on this? Thanks in advance

0

Use this:

echo "99|EOF|$(wc -m <file.txt)" >>file.txt

The command wc -m <file.txt will give the number of characters in the file and then we are putting the desired formatted string at the end of the file.

0

Use the following command:

wc -m test.txt | awk '{print "99|EOF|"$1}' >> test.txt

Explanation:

NAME
       wc - print newline, word, and byte counts for each file

...    
       -m, --chars
              print the character counts

awk '{print "99|EOF|"$1}' prints 99|EOF|<char counted> and >> is used to append output by above command to test.txt

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.