Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add a string to each end of line

Status
Not open for further replies.

cgswong

MIS
Nov 27, 2000
202
US
I'm trying to add a string (e.g. 'TEST END') to the end of each line in a file with say 20 rows but am not having much success as the string ony gets added to the first line. Anyone have any idea as to how to accomplish this? I'd very much appreciate it.

Thanks.
 

hi,

here is a small script that i created i hope that this is what you want.
########################################
#!/bin/sh

COUNT=0
cat 111.txt |while read den
do
echo ${den} >> /tmp/101.txt
COUNT=`expr ${COUNT} + 1`

if test ${COUNT} -ge 20
then
echo "Strings you want to APPEND at LINE 20.... " >> /tmp/101.txt
COUNT=0
fi
done
######################################
good luck...
 
Thanks, this does do the job though it looks as if the formatting has changed but I'll figure it out. It's so simple and obvious I'm embarrassed but sometimes that's just how it goes.... thanks man!
 
Based off your script I created this beauty which works perfectly:

awk '{print $0&quot;TESTING&quot;}' <filename here>

:)
 
Depending on how you want to do this...
you could also edit the file using vi...

#vi <filename>
:1,20s/$/Testing/<enter>

This will replace the end of line character ($) with &quot;Testing&quot; on lines 1-20.

which can also be done in a script like so...

vi <filename> <<EOF>>/dev/null
:1,20s/$/Testing/
:wq!
EOF


Something to toy with if you want....

Good luck!!
Have a Great Day!! :eek:)

soladm
 
cat oldfile | sed -e &quot;s/$/TEST END/g&quot; > newfile
Ged Jones

Top man
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top