Using awk,
create a subdirectory in one directory, for each line in a csv and each line in the csv looks like: first_name,last_name,id_number
need each subdirectory to be in the form "last_name.first_name.id_number"
Please find the following answer for the question using awk script in Unix Shell and added necessary comments, screen shots for your reference.
Note:
1. Using awk, we treat each line as a record through which we can edit the fields and redirect to new file.
2. We can "system" system call in awk to create a directory once we read all the three fields.
Program:
#!/bin/bash
#empty variable
dirName=
if [ $# -ne 1 ]
then
echo "$0 <csv file>"
exit 1
fi
if [ ! -f $1 ]
then
echo "$1: file not present"
exit 1
fi
echo "Enter the directory name, where directories needs to be
created"
read dirName
#check if user enters any name, else take current
directory
#to create directory for each record
if [ ! -z $dirName ]
then
#if directory is not present, create one directory
if [ ! -d $dirName ]
then
mkdir $dirName
if [ $? -eq 0 ]
then
echo "Directory: $dirName
created"
fi
fi
else
dirName=.
fi
#mention delimiter as "," to read field from csv file and pass
the
#directory name to awk script
awk -F"," -v dir_Name=$dirName '
BEGIN { count =0 }
/./ {
tempDir=""
#using sprintf create the command to create a directory
tempDir = sprintf("mkdir %s/%s.%s.%s", dir_Name,$2,$1,$3)
#system command to execute the command
system(tempDir);
#increment the count value for each creation and print at the
end
count++;
}
END { printf("Total number of directories created: %d\n", count) }'
$1
Output:
osboxes@osboxes:~/Chegg/SHELL$ ./dirFromCsv.sh csvFileDr.csv
Enter the directory name, where directories needs to be
created
test1
Total number of directories created: 3
osboxes@osboxes:~/Chegg/SHELL$ ./dirFromCsv.sh
./dirFromCsv.sh <csv file>
osboxes@osboxes:~/Chegg/SHELL$
osboxes@osboxes:~/Chegg/SHELL$ ./dirFromCsv.sh
csvFileDr.csv
Enter the directory name, where directories needs to be
created
.
Total number of directories created: 3
osboxes@osboxes:~/Chegg/SHELL$ ls -ltr|tail
-rw-r--r-- 1 osboxes osboxes 48 Feb 20 20:14 csvFileDr.csv
drwxr-xr-x 5 osboxes osboxes 4096 Feb 20 20:19 test1
-rwxr-xr-x 1 osboxes osboxes 1045 Feb 20 20:21 dirFromCsv.sh
drwxr-xr-x 2 osboxes osboxes 4096 Feb 20 20:22 Bryant.Kobe.24
drwxr-xr-x 2 osboxes osboxes 4096 Feb 20 20:22
James.Lebron.23
drwxr-xr-x 2 osboxes osboxes 4096 Feb 20 20:22
middleton.kris.1
osboxes@osboxes:~/Chegg/SHELL$
osboxes@osboxes:~/Chegg/SHELL$ cd test1
osboxes@osboxes:~/Chegg/SHELL/test1$ ls -ltr
total 12
drwxr-xr-x 2 osboxes osboxes 4096 Feb 20 20:19 Bryant.Kobe.24
drwxr-xr-x 2 osboxes osboxes 4096 Feb 20 20:19
James.Lebron.23
drwxr-xr-x 2 osboxes osboxes 4096 Feb 20 20:19
middleton.kris.1
osboxes@osboxes:~/Chegg/SHELL/test1$
Screen Shot: Note, you can ignore the line numbers present in screen shot and its added for better understanding.


Using awk, create a subdirectory in one directory, for each line in a csv and each...
UNIX Manipulate directory structures. Display the absolute path of your home directory. Create a new subdirectory called COP3353-temp in your home directory. Create a new subdirectory called assign1 in COP3353-temp. Create a new subdirectory called assign2 in COP3353-temp. Display the contents of the directory COP3353-temp. Delete the directory assign2. Display the contents of the directory COP3353-temp. Provide screenshots of each step and processes. Paste your screenshots in word document and send as attachent.
Please answer number 5
CS500 Programming Problems Create a subdirectory of your home directory named sep16 (note the case). Save your solutions in that directory in files named pl.c, p2.c, p3.c, p4. c, and p5. c. Your programs are due Friday September 16 at 4:00PM. You will not receive any credit if your programs are late, have the wrong filename, or are in the wrong directory. 1. Write a C program that reads stdin one character at a time and...
Write an awk script to print just the name and size of ordinary files (do not include directories), one on each line. The output must be aligned as shown in the example below. First, analyze a typical output of the ls -l command to see what differentiates an ordinary file from a directory and which fields contain the file name and size information. Then, determine what the field separator is and whether the default field separator of awk will work,...
Java code to read from .csv file i currently have a .csv file that looks like this: 39.743222, -105.006241, Hospital 39.743981, -105.020017, Home 39.739377, -104.984774, Firehouse 39.627779, -104.839291, McDonald's 39.731919, -104.961814, Chipotle I need to write code to extract the doubles from each line to use for my Linked List. this is what i have so far: Scanner in = new Scanner(new FileInputStream(DATA_FILE));
2. Create a directory using “mkdir” and change into that directory using “cd”. Next, create another directory within the new directory and then change into that directory. Now, run cdwithout any arguments, then run pwd. What do you conclude about the cd command when run with no arguments? 3. You won't find the set command in either /bin or /usr/bin, or in any directory listed in the PATH setting. How is it executed then? (That is, if there is no...
Really need help from 11 on: Create the directory structure IFT383FinalExam/Activities/Activity1 in your home directory. Using the cat command, create a file named classRoster with the following fields, separated by a comma. Student ID First Name Last Name Grade Program of Study ASURITE ID (username) Add three records to your file. Display the contents of the file. Move the file classRoster to the directory Activity1. Go to the Activity1 directory. Display the directory you are in. Add read, write and...
QUESTION 1 From YOUR home directory, execute a find command string that will locate the file called resolv.conf. Include the -exec flag in the find command to cat the file to the screen. Begin your find search from the letc directory Select the correct find command string below that will accomplish this. find /etc-name 'resolv.conf -cat D find /etc-name 'resolv.conf -exec cat 0 find. -name 'resolv.conf -exec cat 0\ find /-name 'resolv.conf' -exec cat 0 QUESTION 2 What find command...
So i am needing to write a one-line awk command to calculate the percentage of a unique word that shows up in field 2 of my comma delimited file using linux terminal. I wanting to calculate the percent that the unique word "10_GOP" shows up in field 2.
Using only shell commands, create a directory structure in your Linux file system to organize files for this course. An example structure may look like the following: osweb homework homework1.c homework2.java homework3.cpp labs lab1 setup.txt projects Include the following by only using shell commands: List the contents of a directory Write data to a text file Print the contents of a text file to the terminal Delete a text file Move a text file to a different directory Rename a...
In a linux command line
Give AWK commands for accomplishing each of the following: Print the 2nd last field (the field directly before the last field) of each line from a file named 'last.txt' Assume you have a file called 'names' that contains a list of people, one person per line. Also, assume that on each line the 3rd field on that line contains the age of the person. Some of the people do not have an age listed, and...