Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Write a template main.c file via shell script to make it easier for yourself later.
The issue here isn't writing the file though, I can do that with echo statements.
What I'd like to see is how to do this in a less redundant way? Note down in the attempts at solution, the amount of echos and >> main$ext is completely unnecessary.
So I'd like to see an alternative, more "efficient for the programmer", way of doing it.
Is there any way to work with a block of text within the shell script?
Edit: I'd also like to avoid all one echo statement with a bunch of "\n" characters, that would ALSO be redundant in my opinion.
2. Relevant commands, code, scripts, algorithms:
ext=".c"
proj="proj"
the echo statement
and >> the append redirection operator
3. The attempts at a solution (include all code and scripts):
The finished product looks akin to 4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of California Davis, Davis, CA, USA, Sean Davis, ECS40
(This is extra work outside of class though so it really has nothing to do with school. I just like shell scripting lately)
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Last edited by Scrutinizer; 04-26-2012 at 05:31 PM..
Scrutinizer is correct, but as there are always several ways in Unix to do something, you could do it with the exec too, if you use ksh (note that this won't work in bash, because bash doesn't have the print command):
This way you won't have to take care of the first ">" and subsequent ">>" redirections (if you mistakenly use ">" it will clear the file) and you will not have to repeat the output files name over and over again.
You could even influence the content of your output file with some program logic in the script - something the here-document provides little support for. For instance, the following would not be possible with a here-doc:
In exchange for helping you I'd like to ask you to learn about I/O channels (file descriptors) and redirection in Unix and how to use these. You might want to read this thread as a starter.
Shell: sh/bash
OS: Linux (all unix flavors)
Suppose i have a variable with this content:
ArgZ='
import os
import sys
MySpecialpath = os.path.abspath(sys.argv)
#
'
ArgZB='#REGEN
#REGEN
#REGEN
'
I want to add this text to a file/script, only under the following conditions:
1. ... (1 Reply)
I have one array SPLNO with approx 10k numbers.Now i want to search the subscriber number from MDN.TXT file (containing approx 1.5 lac record)from the array.if subscriber number found in array it will perform below operation.my issue is that it's taking more time because for one number it's search... (6 Replies)
I have a list of files defined in a single file , one on each line.(No.of files may wary each time)
eg. content of ETL_LOOKUP.dat
/data/project/randomname
/data/project/ramname
/data/project/raname
/data/project/radomname
/data/project/raame
/data/project/andomname
size of these... (5 Replies)
Hi,
I am trying to populate an array with data from a text file. I have a working method using awk but it is too slow and inefficent. See below.
The text file has 70,000 lines. As awk is a line editor it reads each line of the file until it gets to the required line and then processes it.... (3 Replies)
I am having a file, around 500 lines. which contains one letter words, two letters words,...and so on(up to 15 letter words and words are not seprated by line). I need to compare all 1 letter words with 3,4,5 and 6 letters word, all 2 letters words with 2,3,4 and 5 letters words and all 3 letters... (3 Replies)
Hi,
I know the code to write a piece of text to the end of a given text file is
echo $text >> filename.txt
I would like to know how to write a piece of text to a file using shell, but the file name isn't given. I want it to write to whatever text file is currently open. Not to all text files... (2 Replies)
Hi,
I have two text files. Need to create a third text file extracting specific data from first two existing files..
Text File 1: Format contains:
SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010
some text ............so on...and somwhere text like:
Record 1:... (1 Reply)
I need to put together a RAID1 file server for use by Windoze systems. I've built zillions of windows systems from components. I was a HPUX SE for a long time at HP, but have been out of the game for years.
I've got an old workhorse mobo FIC PA-2013 with a 450 MHz K6 III+ I could use, but I'd... (2 Replies)
I need to write value of variable $version at a particular line in a text file.
Line number is determined by another variable &line......I don't know how to do it in shell script ... (2 Replies)
Hello. I have one file that is a collection of discarded emails. Each email is it's own section with each section beginning with the same header (ie 'Another Email' ). I want to traverse through the file and every time I find the header ('Another Email') I then want to pick out the 'To:' line... (5 Replies)