This question is kind of related to my previous question.
This is the output of tree
:
[xyz@localhost Semester1]$ tree
.
├── Eng
│ ├── credits
│ ├── links
│ └── notes
├── IT
│ ├── credits
│ ├── links
│ └── notes
├── IT_workshop
│ ├── credits
│ ├── links
│ └── notes
├── LA
│ ├── credits
│ ├── links
│ └── notes
├── OS
│ ├── credits
│ ├── links
│ └── notes
├── OS_lab
│ ├── credits
│ ├── links
│ └── notes
├── Psy
│ ├── credits
│ ├── links
│ └── notes
├── Python
│ ├── credits
│ ├── links
│ └── notes
└── Python_lab
├── credits
├── links
└── notes
9 directories, 27 files
Now I want to mention the number of credits each course is having in the credits file of the respective folder using cat
.
For example, this is the number of credits each course is having:
Course name | Credits |
---|---|
Eng | 2 |
LA | 3 |
Python | 3 |
OS | 3 |
IT | 3 |
IT_workshop | 1 |
Python_lab | 1 |
OS_lab | 1 |
Psy | 2 |
For adding credits details in Eng/credits, I need to run this:
cat >> Eng/credits
and type the number of credits (i.e., 2) and then press Ctrl+D.
I have to do the same step for the remaining 8 files and it seems like tedious work. Is there any way to do all of this at once using cat
?
I spoke to some friends who are knowledgeable about Bash, and they said that it is better to use echo
or printf
in my case. Why is that so?
I'm expecting to do this:
- In the Eng/credits file, I want the number 2 to be written.
- In the LA/credits file, I want the number 3 to be written.
- In the Python/credits file, I want the number 3 to be written.
- In the OS/credits file, I want the number 3 to be written.
- In the IT/credits file, I want the number 3 to be written.
- In the IT_workshop/credits file, I want the number 1 to be written.
- In the Python_lab/credits file, I want the number 1 to be written.
- In the OS_lab/credits file, I want the number 1 to be written.
- In the Psy/credits file, I want the number 2 to be written.
After reading Hack Saw's answer, I tried this command:
echo {2,3,3,3,3,1,1,1,2} >> {Eng/credits,LA/credits,Python/credits,OS/credits,IT/credits,IT_workshop/credits,Python_lab/credits,OS_lab/credits,Psy/credits}
but it didn't work as I expected it to:
bash: {Eng/credits,LA/credits,Python/credits,OS/credits,IT/credits,IT_workshop/credits,Python_lab/credits,OS_lab/credits,Psy/credits}: ambiguous redirect
cat
a necessity? If you already have the data in a CSV-like format, many other tools would be much more handy. – FelixJN Nov 05 '22 at 15:42cat
. But I would love to see people solve this issue using other commands. I didn't store the data in CSV-like format, but if it's needed, I'm willing to do it. – Random Person Nov 05 '22 at 15:56