Sponsored Content
Top Forums Shell Programming and Scripting Create a file with comment in script Post 302768857 by amazigh42 on Sunday 10th of February 2013 02:36:37 AM
Old 02-10-2013
Quote:
Originally Posted by Scrutinizer
It is really unclear what is required. Is the list_file variable or the output file?
You could try something like this and adjust as required...

Code:
f1() {
  :                             # put your function here
} 

[ $# -eq 1 ] || exit 1          # exit when no file provided
outfile=$1                      # this is the file that the user provides on the command line

while read line; do
  case $line in               
    \#*) echo "$line"           # Skip the comment
         ;;
      *) set -- $line           # split $line into positional parameters
         f1 "$@"                # call f1 with the positional parameters
         ;;
  esac
done < list_file > "$outfile"   # read from list_file, write to $outfile


Sorry Scrutinizer,

You 're right, it's not clear what I said.
I start again.

This my_script.sh

Code:
function f1 {


 } 
 egrep -v '^#' list_file \
 | while read arg1 arg2 arg3 arg4; do 
  f1 $arg1 $arg2 $arg3 $arg4   
done

For information
My function f1 is going to grep the lines between 2 hours (10 to 20) and (08 to 10) respectively in srv4's srv_log and srv3's srv_log.
Then this function f1 will put the results into 2 files named srv4.srv_log.10H-20H and srv3.srv_log.08H-10H.

Here's how I'd like my script works

1st case : I create the list_file before

Quote:
cat > list_file
10 20 srv_log srv4
08 10 srv_log srv3

Ctrl D
Then i launch
Code:
./my_script list_file

2nd case i launch the script without list_file
Code:
./my_script

I would like my_script creates automatically list_file with these comments
Quote:
# Please enter the right variables
# begin_hour...end_hour.....name_log.....name_server

And at the prompt echo

Quote:
"Please fill in this file list_file"
Third case
I launch the script with these parameters
Code:
./my_script 10 20 srv_log srv4

I would like my_script creates automatically list_file with these comments.
Quote:
# Please enter the right variables
# begin_hour...end_hour.....name_log.....name_server

10 20 srv_log srv4
I hope I was clear enough now
I'm sorry again. Thank you for your response.
.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Block Comment in Shell script

how to put multiline comments in a shell script like /* Some code */ in C language? (3 Replies)
Discussion started by: skyineyes
3 Replies

2. Shell Programming and Scripting

Pls comment on my script.

Hi guys, hope you scripting gurus here can help me out, the logic in my script somehow not working the way it should, this script part of a bigger backup script suppose to do some checking on the cluster prior to bringing up the package on MC/SG after backend cloning operation, this portion is... (3 Replies)
Discussion started by: sparcguy
3 Replies

3. UNIX for Dummies Questions & Answers

Why do a unix script starts with a comment?

For eg: #!/usr/bin/ksh <remaining code goes here> .. .. Does the compiler ignores that? Thanks (2 Replies)
Discussion started by: ajincoep
2 Replies

4. Shell Programming and Scripting

Script to put block comment after finding regex in xml file

hi, i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment. so eg.. first block <filter> <filter-name>MyRegEx</filter-name> ... (11 Replies)
Discussion started by: Poki
11 Replies

5. UNIX for Dummies Questions & Answers

multiline comment in shell script

Is thery any way to give comment to multiple line without explicitly specifying # at the begining of each line ? (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

6. Shell Programming and Scripting

Need to comment some code via script

Hi, I am writing a shell script, which should comment a if-fi loop in a file. From google i found that, we can use below qualifier to comment a section of code, :<<COMMENT COMMENT But i could not place these keywords before and after if-fi loop. Any help would be appreciated. Finally the... (2 Replies)
Discussion started by: successlin
2 Replies

7. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

8. Shell Programming and Scripting

sed/awk script to replace only FIRST comment in the file

My first comment on every file contains the license message. I want to replace with a new license message. I used the below sed script, which replaces all comments. What is the modification or any other method with awk script for the below to edit only the first comment(license message)? #sed -f... (1 Reply)
Discussion started by: vpshastry
1 Replies

9. Shell Programming and Scripting

Shell Script Comment code blocks in a bash source file

Just began to learn on Shell Script. I got an exercise from my friend. I know how to make this happen in C, but I'm not familiar with Shell Script. Hope I can get some help from all of you. I want to write a bash script to comment code blocks in a bash source file. What I mean comment is '#', I... (1 Reply)
Discussion started by: HiFuture0801
1 Replies

10. UNIX for Beginners Questions & Answers

Remove Comment Lines From Script/Input File

Hello, I have a SAS code that predominantly has comments line and the real code like below and i want to remove ONLY THE COMMENTS from the code in the single line or spanned across multiple lines. /******************************************************************** *** This Is a Comment... (4 Replies)
Discussion started by: arooonatr
4 Replies
All times are GMT -4. The time now is 11:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy