Question

Can you comment notes along with the code so I can follow along and understand what is being written?? Thanks in advance!Lets say were in a directory and we want to rename every file ending in·c, to end in .C (i.e., capitalize the c). Heres o

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The question is to to rename .c file to .C extension in the directory

So there are various ways shown here, comments with respect to code are as:

1.

$ for i in *.c     // this line will iterate over all file which is ending with .c extension

do b = 'basename "$i" .c' ; //getting basename of file with extension .c

mv "$b.c" "$b.C"   //renaming .c files to .C extensions

done

2. Suppose you have complex renaming like output.XXX where XXX varies from 000 to 999 and earlier a simulation parameter was 10 so the file name were like output.p10.XXX, so now you want to change that simulation parameter to 20 then file name will be like output.p20.XXX. So first how to make files name like output.p10.XXX :

for i in output.*; //iterate over all the files in directory

do ls output.* (//give list of all the files with named output) | sed 's/output\.//' (//this will seperate output and XXX from file name, you can also use ; in place of / after s as a seperator of files given by ls but it can cause problem discussed later) | awk 'printf{"mv output.%d output.p10.%d\n",$1,$1}' (//this will make file output.XXX to output.p10.XXX and $1 is equal to XXX as using sed we seperated so the XXX is stored in 1 position and it is accessed through $1) | sh

3. Here you can write above thing in rename.sh file and execute directly as

rename ';\.c$;.C' *.c it will change all file .c to .C

rename ';\.;.p10.;' output.* it will change output.XXX to output.p10.XXX file name

4.

Here rename -f option is to force fully rename the files as without -f there will be warnings

5.

We should not use / in seperator as directory itself can have / in path name so that will cause problem as :

rename ';\.c$;.C' src/*.c it will change all file .c to .C

rename ';\.;.p10.;' sim-output/output.* it will change output.XXX to output.p10.XXX file name

src is different directory and sim-output is different directory. Here / is included in path so can't use / as seperator as discussed above.

Add a comment
Know the answer?
Add Answer to:
Can you comment notes along with the code so I can follow along and understand what is being written?? Thanks in advance...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Help Please! This is a problem that I have been stuck on.I am only suppose...

    Python Help Please! This is a problem that I have been stuck on.I am only suppose to use the basic python coding principles, including for loops, if statements, elif statements, lists, counters, functions, nested statements, .read, .write, while, local variables or global variables, etc. Thank you! I am using python 3.4.1. ***( The bottom photo is a continuation of the first one)**** Problem statement For this program, you are to design and implement text search engine, similar to the one...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check...

    LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check the output) Display the command(s) used to do the following: create an empty file called history by using just a redirection operator. Verify and show. Show/verify all results (i.e., all commands and their corresponding outputs). Wait 1 minute or more and then display the command(s) used to do the following: change the timestamp on the history file you just created. Verify/display the change. Show/verify...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • I have the following code....from the previous lab....the above needs to be added to what is...

    I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing)    pid_t pid;    int j;    //printf("Welcome to Project Three\n”);    // For loop*/    for (j = 1; j...

  • Hello, I am wondering what the source code for this problem would be. Thank you so...

    Hello, I am wondering what the source code for this problem would be. Thank you so much. You will write a java program using the Eclipse IDE. The program will allow a user to perform one of two options. The user can look up the dates for a given zodiac sign or enter a date and find what sign corresponds to that date. SIGN START DATE END DATE Aries 3/21 4/19 Taurus 4/20 5/20 Gemini 5/21 6/20 Cancer 6/21 7/22...

  • MATLAB question: I have written a code to solve for a metals resitance. Here is the...

    MATLAB question: I have written a code to solve for a metals resitance. Here is the problem statement: Part 1 (Algorithms) – due Friday: Think about how you might solve the problem of calculating the resistance of a given group of metals depending on the type of metal, the length of the wire and the area of the wire (if given the diameter only – so you must calculate the area). Write instructions (an algorithm) for a script that behaves...

  • 1 Overview The goal of this assignment is to help you understand caches better. You are...

    1 Overview The goal of this assignment is to help you understand caches better. You are required to write a cache simulator using the C programming language. The programs have to run on iLab machines. We are providing real program memory traces as input to your cache simulator. The format and structure of the memory traces are described below. We will not give you improperly formatted files. You can assume all your input files will be in proper format as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT