07-04-2009
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
#c
#d
#d
#e
I kept getting error while attempting to use break
awk ' if ( $1 ~ /^c/ ) { beginline = NR ; break } '
Greatly appreciate your comment
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all
I need to strip blank lines from the end of a file. I have searched and found topics on how to strip lines from the entirety of a file - however I need to limit this to only the last 3-4 lines.
Any ideas?
Thanks (4 Replies)
Discussion started by: saabir
4 Replies
2. Shell Programming and Scripting
I have a text file with two coulmn
first column is just used in to show the line number, these line number are not there in the real file.
I want to delete the line 16(in this file) here, even tough there is no data inside it . this empty line is causing me a problem by throwing me garbage... (12 Replies)
Discussion started by: shashi792
12 Replies
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. UNIX for Dummies Questions & Answers
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
6. Shell Programming and Scripting
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:
-- select salary from emp where empname = 'URS' ; (3 Replies)
Discussion started by: omega3
3 Replies
7. Shell Programming and Scripting
I really can't figure this one out.
I have 2 files, one file is a list of hostnames and the other is a list of their corresponding IPs:
fileA:
example.com
another.org
thirdie.net
fileB:
1.1.1.1
2.2.2.2
3.3.3.3
I want to create a fileC that looks like:
example.com 1.1.1.1... (2 Replies)
Discussion started by: zstar
2 Replies
8. Shell Programming and Scripting
I have a file as follows:
0
1056
85540
414329
774485
1208487
1657519
2102753
2561259
3037737
3458144
3993019
4417959
4809964
5261890
5798778
6254146
I want to find all lines between a specified start and end tag. (6 Replies)
Discussion started by: jamie_123
6 Replies
9. Shell Programming and Scripting
Hello,
I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies
10. UNIX for Beginners Questions & Answers
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