UNIX, URGENT, Short problem How do i change this grep command to send the header
ID: 3717382 • Letter: U
Question
UNIX, URGENT, Short problem
How do i change this grep command to send the header layout to either project3.df.output or project3.ui.output would you just change the "24" in the grep line to "df"? and would the out_file=project3.df.output
if [ `echo $1 | grep -c "24" ` -gt 0 ] #check if command line argument contains 24 or not
then
out_file=project2.24.out #set the out file to project2.24.out
else
out_file=project2.12.out #set the out file to project2.12.out
fi
echo "**************">$out_file #write the line to file in write mode so that file would get created or replaced
echo "">>$out_file #write the line to file in append more so that the line gets added in end of the file
echo "Student name : ">>$out_file #write the line to file in append more so that the line gets added in end of the file
echo "Project 2 CIS 129 Sec #">>$out_file #write the line to file in append more so that the line gets added in end of the file
echo $current_time>>$out_file #write the line to file in append more so that the line gets added in end of the file
echo "**************">$out_file #write the line to file in write mode so that file would get created or replaced
Explanation / Answer
Hi,
if [ `echo $1 | grep -c "24" ` -gt 0 ] #check if command line argument contains 24 or not
then
out_file=project2.24.out #set the out file to project2.24.out
else
out_file=project2.12.out #set the out file to project2.12.out
this block here is where you need to change where to direct the o/p to. in the current logic, if the command line arguement has 24 it is being sent to first file otherwise to the second, so as per your requirement to change the o/p filenames if based on same condition then it should be
if [ `echo $1 | grep -c "24" ` -gt 0 ] #check if command line argument contains 24 or not
then
out_file=project2.24.out #set the out file to project3.df.output
else
out_file=project2.12.out #set the out file to project3.ui.output
Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.