I am not sure what I am doing wrong here. The code should work fine. I have been making small changes insuring that each new bit works. Now running my sed through multiple files I am getting incorrect output. Any help and instruction would be greatly appreciated.
The problem -
Generalize your sub2 script, producing a new script sub3 that will apply a substitution to any number of files given on the command line. For example
should apply the same substitution throughout each of the three files named there.
Give the command:
to complete the assignment.
My code -
Results -
I do not know what test 28 inputs or the contents of _aadvark.cpp. We run a given command and it automatically tests our script. If it passes a test we see:
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Old Dominion University - Norfolk, Va USA
Professor Steven Zeil
CS 252 - An Introduction to Unix for Programmers
Last edited by Don Cragun; 12-06-2013 at 12:39 AM..
Reason: Add more CODE tags.
Okay, I changed the code to
And received the error
for test 28.
So then I changed my script to -
Which passes test 28, but fails test 29 and does not address what you were saying.
How would I go about referring to file? Setting $p3=file while inside the loop? The one example in the slides we have is
And it uses that snippet repeatedly.
And the failed test output is -
I think I see what is wrong here, having 3 argument parameters and it giving four, but how do I account for X number of files?
Did it look like you were getting the correct set of arguments to give to sed when you tried my sample script? (Did you try my sample script before changing it?)
Why did you change:
in your original code and in my example to:
The shell expands "$@" to a list of the quoted arguments remaining on your command line after the shift commands removed your first two command-line arguments. The shell expands * to a list of files in the current directory.
These 2 Users Gave Thanks to Don Cragun For This Post:
I repeat: Did you try my sample script before changing it?
Please try the sample script I gave you without changing it. (Note that there is a HUGE difference between $FILE and $file.) Using:
and referencing $file in the loop won't work.
This User Gave Thanks to Don Cragun For This Post:
Hey everyone! I made a shell script that would go through a file and replace any phrase or letter with another phrase or letter. Helps update variable names or values. The following code is this:
#!/bin/sh
Word1="$1"
Replace1="$2"
File1="$3"
arg=$( echo "$Word1" | sed 's:\:\\&:g' )... (3 Replies)
Hi, I was hoping that someone could help me. I have a problem that i am trying to work on and it requires me to change text within multiple files using sed. What i have so far is
!/bin/sh
File1="$3"
File2="$4"
File3="$5"
testNum="$File1"
while test "$testNum" <= "$File3";
do
echo... (12 Replies)
Hi, I was hoping that someone could help me. I have a problem that i am trying to work on and it requires me to change text within multiple files using sed. I use the program to change an occurance of a word throughout different files that are being tested. At first i had to Create a new script,... (1 Reply)
Hi,
i use the below script to send a single file to remote server from linux.
ftp -nvi <<!EOF
open $Host_name
user $USER_ID $PWD
binary
mput $file_name
quit
!EOF (where i... (2 Replies)
Hey guys,
I'm really new to UNIX and shell scripting in general. For my internship I need to rename a bunch of files. Specifically, I need to change the first letter of each of the files to lowercase and I have to change the endings so they all basically look like "file_cone.jpg". I know I... (4 Replies)
Hi All,
I am a beginner for shell programming. I have a requirement to ftp multiple files. Here are the details.
I have around thiry files in one directory, I want a shell script which selects 5 files at a time and does ftp them to another host . After the transfer for first files is... (0 Replies)
Hi,
I need help to split lines from a file into multiple files.
my input look like this:
13
23 45 45 6 7
33 44 55 66 7
13
34 5 6 7 87
45 7 8 8 9
13
44 55 66 77 8
44 66 88 99 6
I want to split every 3 lines from this file to be written to individual files. (3 Replies)
I am a new to Linux and try to write a script to join three multiple files.
For example, there are three files
file1
# comment
a Kevin
b Vin
c Sam
file 2
# comment
a 10
b 20
c 40
file 3
# comment
a blue
b yellow (7 Replies)
I have a file (email) containing email addresses.
I have a second file (terms) that contains simple regular expressions and words/characters. Here are some examples:
\.trainee
\.group
\.web
I want to go through email and delete lines containing the expressions/words from terms and write... (1 Reply)
hi,
how to send multiple files from the shell script
eg : i have
/home/adm/file1
/home/adm/file2
/home/adm/cfg
how can i attach these files in the mail ? (1 Reply)