Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file?
I am using this on Docker Quickstart Terminal version 19. I can't seem to execute it on the command line or get it to work. I'm not sure what I have to fix.
This is what I have written so far.
----------------------------------------------------
JennyM07@DESKTOP-3XD60LM MINGW64 ~/CIT270/Lab_1$ ls -l
total 1
-rwxr-xr-x 1 JennyM07 197121 100 Aug 26 21:41 file8.sh*
-rw-r--r-- 1 JennyM07 197121 0 Aug 26 21:43 file8.txt
JennyM07@DESKTOP-3XD60LM MINGW64 ~/CIT270/Lab_1$ cat
file8.sh
#! bin/bash
insert='GHIJKLM'
file='file8.txt'
awk '1;!(NR%10) {print $insert;}' $file
exit 1
JennyM07@DESKTOP-3XD60LM MINGW64 ~/CIT270/Lab_1$
./file8.sh
bash: ./file8.sh: bin/bash: bad interpreter: No such file or
directory
JennyM07@DESKTOP-3XD60LM MINGW64 ~/CIT270/Lab_1$ bash file8.sh
---------------------------------------------------------------------------------------------------
The code could not execute because there was a slash missing before the word bin on the first line. I see you already have execute permission +x for your .sh file. So that is not the issue.
I have also fixed the awk command . -v is used to pass the bash variable insert to awk variable ins. Please do rate the answer if it helped. Thank you.
#!/bin/bash
insert='GHIJKLM'
file='file8.txt'
awk -v ins="$insert" ' {print;} NR % 10 == 0 { print ins;} '
$file
exit 1
Get Answers For Free
Most questions answered within 1 hours.