Comment ( -- ) lines from 10 to 25 for every .sql file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comment ( -- ) lines from 10 to 25 for every .sql file
# 1  
Old 04-30-2013
Comment ( -- ) lines from 10 to 25 for every .sql file

Platform : RHEL 5.4


I have several .sql files in a directory. I want to comment lines 10 to 25 for all .sql files.
How can I do this ?

The symbol for comment in SQL is --

eg:
Code:
-- select salary from emp where empname = 'URS' ;

# 2  
Old 04-30-2013
Try:
Code:
sed '10,25 s/\(.*\)/-- \1/' infile.sql

# 3  
Old 04-30-2013
To process all of the sql files in the current directory at once, you could try:
Code:
ec=0
for i in *.sql
do      if sed '10,25s/^/-- /' $i > tmp$$.sql
        then    mv tmp$$.sql $i
        else    ec=1
                rm -f tmp$$.sql
        fi
done
exit $ec

# 4  
Old 04-30-2013
And just for grins yet another 1 liner...
Code:
for i in *.sql ; do ex -s +"10,25 s/^/-- / | wq" $i ; done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Sql multi line comment /* shell interpretation issue

Greetings Experts, I do have some basic knowledge of Unix. The task I am trying to do through shell script is to generate the view script for all of the tables which is in YYYYMMDD format (I assume I am on Ksh). I have certain tables that ends in YYYYMMDD format (eg: tbl_20150630) For each... (1 Reply)
Discussion started by: chill3chee
1 Replies

3. UNIX for Dummies Questions & Answers

Comment lines in file without vi editor

Legends, Can you please help me in following. I need to comment lines from “/tmp/a.txt” from the line A to line B through the command prompt only. Please use variables not direct values like 2 or 5 It can be done with VI editor but it's not matches with my requirement (: 2,5 s/^/#/g). ... (1 Reply)
Discussion started by: sdosanjh
1 Replies

4. UNIX for Advanced & Expert Users

SQL script with 86000 lines: new files with only 10000 lines (per file)

Hi this is my SQL script $ wc -l insert_into_customers.sql 85601 insert_into_customers.sqlI wish to cut this file into 9 files each 10000 lines (the last one less) $ wc -l insert_into_customers_00*.sql 10000 insert_into_customers_001.sql 10000 insert_into_customers_002.sql ... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

5. Shell Programming and Scripting

Comment lines in FSTAB using perl

Hi All, I need to comment specific Two Lines in fstab & want to do using & also want to ensure that is done corretly. I am trying the below method. But its giving Search pattern not terminated. ################ b36376 67 % cat linux-fstab_testing | perl -i -wnl -e '/^('\Q... (1 Reply)
Discussion started by: ajaincv
1 Replies

6. Shell Programming and Scripting

How can i comment out a section between two particular lines

I want to find out which files under /etc have the the following section: and then i would like to comment out the above section in all the files. Please help. (3 Replies)
Discussion started by: proactiveaditya
3 Replies

7. Shell Programming and Scripting

how to find and comment out lines in one file against another file

I have 2 files: fileA and fileB. content of fileA --------------- admin.teacher is in new york; admin.mason is in new york; admin.driver is in new york city; user.trucker is in hartford; admin.developer is in new york state; content of fileB ---------------- admin.teacher is in... (2 Replies)
Discussion started by: lowprofile
2 Replies

8. Shell Programming and Scripting

using awk to comment out lines to the end of file

Hello, I have a file as follow a b c c d d e I would like to write a awk command to insert # from the first occurence of "c" to the end of the files. OUTPUT should be like this a b #c (5 Replies)
Discussion started by: phamp008
5 Replies

9. UNIX for Dummies Questions & Answers

comment lines

Is there a command to put a comment (#) in a whole part of a shell script? (5 Replies)
Discussion started by: vero_81
5 Replies

10. Shell Programming and Scripting

how to comment multiple lines in unix

hi all, please help me how to comment multiple lines in unix script. thanks in advance --bali (3 Replies)
Discussion started by: balireddy_77
3 Replies
Login or Register to Ask a Question