Selecteing only non commented rows


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Selecteing only non commented rows
# 1  
Old 10-01-2008
Selecteing only non commented rows

Hi,

I have develop a script that will read a single line from file and do some operations.But now my problwm is that if in that file suppose 1 line is commented, then i have to ignore that line...Can anybody help me out to solve this issue?Smilie Details are:

Script:

HTML Code:
#!/bin/sh
Parmdir=/opt/home/xyz
cat $Parmdir/jobname.lst | while read line
do
some command
done
cat jobname.lst
HTML Code:
ABCD
EFGH
#AFFF
RRRRR
So in the above script i have to ignore the 3rd line.Smilie

Please help me.Smilie

Thanks In Advance!
# 2  
Old 10-01-2008
The simplest way would to add a simple grep that ignores lines starting with #... like so

cat $Parmdir/jobname.lst | grep -v ^# | while read line

The "^" character, in case you're not familiar, specifies the beginning of a line. So if we group that with the -v (invert matching, aka do not print matching lines) it states do not print any lines that begin with the hash mark. (#)

Enjoy!

Quote:
Originally Posted by Amey Joshi
Hi,

I have develop a script that will read a single line from file and do some operations.But now my problwm is that if in that file suppose 1 line is commented, then i have to ignore that line...Can anybody help me out to solve this issue?Smilie Details are:

Script:

HTML Code:
#!/bin/sh
Parmdir=/opt/home/xyz
cat $Parmdir/jobname.lst | while read line
do
some command
done
cat jobname.lst
HTML Code:
ABCD
EFGH
#AFFF
RRRRR
So in the above script i have to ignore the 3rd line.Smilie

Please help me.Smilie

Thanks In Advance!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comment all lines which are not already commented for each full path pattern matched

Hello. Question 1 : I want to comment out all lines of a cron file which are not already commented out for each full path pattern matched. Example 1 nothing to do because line is already commented out; pattern = '/usr/bin/munin-cron' # */5 * * * * munin test -x... (3 Replies)
Discussion started by: jcdole
3 Replies

2. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

3. Shell Programming and Scripting

how do i prevent $ from being commented out if no value is present? (Bash Script)

Hey guys, I want to paste a code in a .php file via a bash script. I am on ubuntu 10.04. The problem is if the values for $ aren't present, then all of them would be removed by the script. An example of my script (I modified it for this thread to prevent it from being overly complicated) ... (2 Replies)
Discussion started by: xxxx
2 Replies

4. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

5. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

6. Programming

to count the number of commented lines in a file

can someone guide me how to have a C pgm to count the number of commented lines? (3 Replies)
Discussion started by: naan
3 Replies

7. HP-UX

inittab always restarts a process which was commented out

I have a script that reads the /etc/inittab file and puts a # in front of the line with my program. Then I do a "init q". But the process is restarted at once. :confused: I need the process stopped, because I want to replace the binary! Who can advise? (2 Replies)
Discussion started by: uludwig04
2 Replies
Login or Register to Ask a Question