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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add text to a file after every 10 lines ? 1

Status
Not open for further replies.

lotamoka

MIS
Jul 15, 2007
43
US
I have file like this
libv lib11 BW1079 rem=bulk checkl=no force=yes
libv lib11 BW1560 rem=bulk checkl=no force=yes
libv lib11 BW1924 rem=bulk checkl=no force=yes
libv lib11 BW1947 rem=bulk checkl=no force=yes
libv lib11 BW1951 rem=bulk checkl=no force=yes
libv lib11 BW1960 rem=bulk checkl=no force=yes
libv lib11 BW1965 rem=bulk checkl=no force=yes
libv lib11 BW1968 rem=bulk checkl=no force=yes
libv lib11 BW2013 rem=bulk checkl=no force=yes
libv lib11 BW2021 rem=bulk checkl=no force=yes
libv lib11 BW1079 rem=bulk checkl=no force=yes
libv lib11 BW1560 rem=bulk checkl=no force=yes
libv lib11 BW1924 rem=bulk checkl=no force=yes
libv lib11 BW1947 rem=bulk checkl=no force=yes
libv lib11 BW1951 rem=bulk checkl=no force=yes
and i want to add following text after 10th line

echo "Please Remove the Tapes from the Library"
echo "Press enter when the tapes have been removed\c"
read
sleep 2
echo " Ejecting the next 10 Tapes"

Is there any way we can do with awk ?
 
Hi Feherke
What would be above command when text to be added is from another file ?
Your help very much appreciated.
THX again
 
Hi
Above suggestion worked. I am trying to understand ..can u explain each peices from below ?
awk '{print}!(NR%10){system("cat test1")}' test
 
Hi

Code:
awk '
{                      [gray]# do it for all input records[/gray]
  [b]print[/b]                [gray]# print the current record *[/gray]
}
!(NR%10) {             [gray]# do it if the record number is divisible with 10 **[/gray]
  system([i]"cat test1"[/i])  [gray]# execute external command[/gray]
}
' test
[gray]*[/gray] - [tt]print[/tt] is the same as [tt]print $0[/tt]
[gray]**[/gray] - [tt]!(NR%10)[/tt] is the same as [tt]NR%10==0[/tt]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top