UNIX SCRIPT Consider the files L2E1.iva , L2E2.iva , and L2E3.iva from your lab2
ID: 3739928 • Letter: U
Question
UNIX SCRIPT
Consider the files L2E1.iva, L2E2.iva, and L2E3.iva from your lab2E. This is raw performance data collected on a solar photovoltaic module installed at the ASU Polytechnic campus. This data must be processed to determine the performance output of the system or panel. The 3 files correspond to 3 repeated measurements.
Write a shell script called lab5.2 which uses the tools you have learned in this unit, including at least one use of regular expressions, grep, sed, paste, and awk, to extract, edit and format the necessary data from the three files to resemble the processed data below:
Performance Data
Curve Name gge0001x gge0001y gge0001z
Date 12/30/2006 12/30/2006 12/30/2006
Time 14:15 14:15 14:16
Tamb (°C) 15.8 16.1 15.0
Tref (°C) 30.1 29.6 29.9
Tm (°C) 20.2 22.3 23.4
Irradiance (W/m^2) 1006.2 1003.5 999.8
Isc (A) 8.40 8.41 8.37
Voc (V) 37.14 36.82 36.62
Imp (A) 7.55 7.53 7.44
Vmp (V) 28.19 27.90 27.86
Pm (W) 212.86 210.15 207.15
FF (%) 68.3 67.9 67.6
L2E1.iva - https://justpaste.it/1iy4c
L2E2.iva - https://justpaste.it/1iy4g
L2E3.iva - https://justpaste.it/1iy4j
Explanation / Answer
Please find my answer:
Here i will give you how to use commands the like grep, sed, paste, awk. You can try it on your own i will give you a step by step process foe every command.
grep
The grep command is used to search text. It searches the given file for lines containing a match to the given strings or words. It is one of the most useful commands on Linux and Unix-like system.
The grep command syntax
The syntax is as follows:
use grep to search a file
Search /etc/passwd file for boo user, enter:
$ grep boo /etc/passwd
grep to search words only
When you search for boo, grep will match fooboo, boo123, barfoo35 and more. You can force the grep command to select only those lines containing matches that form whole words i.e. match only boo word:
$ grep -w "boo" file
count line when words has been matched
The grep can report the number of times that the pattern has been matched for each file using -c (count) option:
$ grep -c 'word' /path/to/file
Pass the -n option to precede each line of output with the number of the line in the text file from which it was obtained:
$ grep -n 'root' /etc/passwd
list just the names of matching files
Use the -l option to list file name whose contents mention main():
$ grep -l 'main' *.c
Finally, you can force grep to display output in colors, enter:
$ grep --color vivek /etc/passwd
sed
SED command in UNIX is stands for stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it.
Replacing or substituting string : Sed command is mostly used to replace the text in a file. The below simple sed command replaces the word “unix” with “linux” in the file.
Replacing the nth occurrence of a pattern in a line : Use the /1, /2 etc flags to replace the first, second occurrence of a pattern in a line. The below command replaces the second occurrence of the word “unix” with “linux” in a line.
Output:
Deleting lines from a particular file : SED command can also be used for deleting lines from a particular file. SED command is used for performing deletion operation without even opening the file
Examples:
1. To Delete a particular line say n in this example
2. To Delete a last line
3. To Delete line from range x to y
5. To Delete from nth to last line
awk
Awk is a scripting language used for manipulating data and generating reports.The awk command programming language requires no compiling, and allows the user to use variables, numeric functions, string functions, and logical operators.
Awk is a utility that enables a programmer to write tiny but effective programs in the form of statements that define text patterns that are to be searched for in each line of a document and the action that is to be taken when a match is found within a line. Awk is mostly used for pattern scanning and processing. It searches one or more files to see if they contain lines that matches with the specified patterns and then performs the associated actions.
Syntax:
Default behavior of Awk : By default Awk prints every line of data from the specified file.
Print the lines which matches with the given pattern.
Spliting a Line Into Fields : For each record i.e line, the awk command splits the record delimited by whitespace character by default and stores it in the $n variables. If the line has 4 words, it will be stored in $1, $2, $3 and $4 respectively. Also, $0 represents the whole line.
NR: NR command maintains a present day be counted of the quantity of enter information. keep in mind that statistics are normally lines. Awk command plays the sample/movement statements once for each record in a document.
NF: NF command keeps a remember of the range of fields within the modern input file.
FS: FS command incorporates the sector separator person which is used to divide fields at the enter line. The default is “white space”, that means area and tab characters. FS can be reassigned to every other man or woman (generally in begin) to change the field separator.
RS: RS command stores the cutting-edge report separator character. given that, via default, an enter line is the input file, the default record separator character is a newline.
paste
Paste command is one of the useful commands in Unix or Linux operating system. It is used to join files horizontally (parallel merging) by outputting lines consisting of lines from each file specified, separated by tab as delimiter, to the standard output. When no file is specified, or put dash (“-“) instead of file name, paste reads from standard input and gives output as it is until a interrupt command [Ctrl-c] is given.
Syntax:
Let us consider three files having name state, capital and number. state and capital file contains 5 names of the Indian states and capitals respectively. number file contains 5 numbers.
Without any option paste merges the files in parallel. The paste command writes corresponding lines from the files with tab as a deliminator on the terminal.
In the above command three files are merges by paste command.
-d (delimiter): Paste command uses the tab delimiter by default for merging the files. The delimiter can be changed to any other character by using the -d option. If more than one character is specified as delimiter then paste uses it in a circular fashion for each file line separation.
-d (delimiter): Paste command uses the tab delimiter by default for merging the files. The delimiter can be changed to any other character by using the -d option. If more than one character is specified as delimiter then paste uses it in a circular fashion for each file line separation.
–version: This option is used to display the version of paste which is currently running on your system.
Combining N consecutive lines: The paste command can also be used to merge N consecutive lines from a file into a single line. Here N can be specified by specifying number hyphens(-) after paste.
Combination with other commands: Even though paste require at least two files for concatenating lines, but data from one file can be given from shell. Like in our example below, cut command is used with -foption for cutting out first field of state file and output is pipelined with paste command having one file name and instead of second file name hyphen is specified.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.