Question

Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line...

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

---------------------------------------------------------------------------------------------------

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
drwxr-xr-x 10 mst staff 320 Sep 18 14:58 Sites drwxr-xr-x 2 mst staff 64 May 28...
drwxr-xr-x 10 mst staff 320 Sep 18 14:58 Sites drwxr-xr-x 2 mst staff 64 May 28 2017 VirtualBox VMs -rw-r--r-- 1 mst staff 633 Dec 11 2019 balance.pl drwxr-xr-x 4 mst staff 128 Oct 11 2014 bin -rw-r--r-- 1 mst staff 473 Dec 13 2019 bitshift.py For this problem, we are mainly concerned with the set of access permissions, which appears at the beginning of the line for each file or directory. Directories have a "d" at the beginning of...
NOTE: I just need the answer for question 5 and 6. I already knew the question...
NOTE: I just need the answer for question 5 and 6. I already knew the question 1-4, and wrote down all the requirements for clarification. In this assignment, you are required to write a Bash script, call it assignment2.sh. Your Bash script has to accept at least four input arguments, and must: 1) Print to the user a set of instructions explaining how the PATH variable can be used in Bash. 2) Save the manual of the 'awk' command in...
Linux, please avocado is an empty file Q14 – Specify a single line command that gives...
Linux, please avocado is an empty file Q14 – Specify a single line command that gives the owner and group permission to execute the file avocado while giving the owner sole permission to read and write the file. Do not change any other permission, i.e., do not remove permission from others to execute the file, if they already have that permission. Q15 – File/directory permissions are subject to permissions on the parent directories. For example, consider the file /home/dv35/cs265/lab1.txt. If...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of userids on the command line 2. For each userid, display the userid, PID, CPU time, and current command for each process owned by that userid Your output should look similar to this example: practice-script-a doug.jones User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND: /usr/lib/systemd/systemd --user User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)    User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd: doug.jones@pts/5 User: doug.jones...
In the script below, where should I insert the break command so that the code produces...
In the script below, where should I insert the break command so that the code produces the following output: 10 11 12 26 a = 10; for i=a:i+10 if( a<13 ) ...(1)... disp(a); a = a+1; ...(2)... else disp(a*2); ...(3)... end ...(4)... end a. (4) b. (1) c. (3) d. (2)
In UNIX .Write a bash script that takes a list of usernames as its command line...
In UNIX .Write a bash script that takes a list of usernames as its command line arguments and displays on the screen, for each user name, a message of the form Number of times that logged into this machine is where is to be replaced by the number of recors that the last command output that match exactly. For example, if i enter command logincount mark it should output something like number of times that sweiss logged into this machin...
1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal...
1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal using the user name of root and the password of LINUXrocks!. 2. At the command prompt, type vi diskconfig.sh and press Enter to open a new file for editing called diskconfig.sh in your home directory. Why is it good form to use a .sh extension for shell scripts? 3. Enter the following text into the diskconfig.sh file. As you are typing the contents, ensure...
The first script you need to write is login.sh, a simple script that you might run...
The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of...
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
1. By convention, how are configuration files separated from regular files? (NOTE: A practical effect of...
1. By convention, how are configuration files separated from regular files? (NOTE: A practical effect of the separation is that they are not displayed by the default version of the ls command)                         a. the prefix "rc" (rc.filename)               c. the extension .cfig                         b. a dot (.) at the beginning                    d. by having the SUID bit set 2. The IP address which is reserved for local loopback (equivalent to "localhost") is:                         a. 255.255.255.0                                   c. 192.168.70.1...