Trying to show lines in INI files until the comment character (#)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Trying to show lines in INI files until the comment character (#)
# 1  
Old 09-18-2010
Trying to show lines in INI files until the comment character (#)

I have a working directory on a server with over 100 INI files. For the most part, they are configured the same way. Each line will contain 1 or none variables listed from the first character in the line such as VariableName=0.

Unfortunately there are comments everywhere using the poundsign.

I have created a looping grep - I grep all files for one particular variable - so that all of the same settings in the files are stacked one upon the other for easy review. Then the loop move to the next variable name in my list.

My problem is this. I use the following line to omit where the comment text might state directions to set the variable = this or that for these reasons:

Code:
grep $varEQ *.ini | grep -v '#' >> /tmp/ini_FTP_settings_$INTFC.lst;

This blocked lines where the vaiable was set and then a comment was appended in the line of text after the variable was set, such as

Code:
VariableZ=0     # Remember to never set this variable to 1.

This is probably a newbie type question, but how do I bring back the VariableZ=0 portion and nothing after the # sign? If the pound sign is the first character in a line, I don't want to report any of that line either.

Any help would be appreciated.

- Dann "hindesite" Hindes
# 2  
Old 09-18-2010
Code:
grep $varEQ *.ini | sed -n 's/\(.*\)#.*/\1/p' >> /tmp/ini_FTP_settings_$INTFC.lst

# 3  
Old 09-19-2010
Code:
sed  "/${varEQ}/ s/#.*//" *.ini>> /tmp/ini_FTP_settings_$INTFC.lst

# 4  
Old 09-21-2010
Quote:
Originally Posted by john1212
Code:
grep $varEQ *.ini | sed -n 's/\(.*\)#.*/\1/p' >> /tmp/ini_FTP_settings_$INTFC.lst

John1212: I think yours has the greatest chance of working. At this point, it does not. When a line is encountered with a pound sign, nothing is returned and appended to my output. (What is appended is the filename: portion of the stdout from grepping across multiple files.) Is there a small sytax error in your sed substitution code? I am not good at sed yet, and would appreciate you looking at it a second time.

Danny H., hindesite
# 5  
Old 09-21-2010
Dear hindesite!!
For me, your comment about my chance is unnecessary.
You work though you 'not good at sed yet'.
I recall you, 'grep' you written.
What for do I know that you don't want the name of ini files ?

boy, and so seriously,
who are interested in the existence of the text in the collection of *. ini, and do not want to know where.
Learn. Learn. Learn the logic. Learn about "grep" too.

Bye.

Last edited by john1212; 09-21-2010 at 08:05 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: copying lines with specific character to files with same name as copied line.

I am trying to make my script as simple as a possible but, I am not sure if the way I am approaching is necessarily the most efficient or effective it can be. What I am mainly trying to fix is a for loop to remove a string from the specified files and within this loop I am trying to copy the lines... (2 Replies)
Discussion started by: Allie_gastrator
2 Replies

2. UNIX for Dummies Questions & Answers

Append two lines of text to php.ini in the entire directory tree.e

I am looking to write a script that will read the php.ini files on my web host. If the two lines do exist do nothing. If not append two lines to the end of it then move on to the next directory and open the next php.ini file. I have the beginning of one that was given to me on another web site but... (6 Replies)
Discussion started by: Larrykh465
6 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. 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

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

6. Shell Programming and Scripting

sed show lines text between 2 blank lines

I have a file like blah blah blah blah this is the text I need, which might be between 1-4 lines, but always has a blank line above and below it, and is at the end of the text file the code tags don't show the trailing blank line. I started by deleting the last blank line with: ... (2 Replies)
Discussion started by: unclecameron
2 Replies

7. Shell Programming and Scripting

script assistance needed - create an archive of INI files

First and foremost - me != unix bubba. Here is the situation. We have a box with data AND settings in the same directory path. (Data files aren't in the SAME directories as settings.) I need a script that generates a tarred-up archive of only the INI files with the directory structure. We... (2 Replies)
Discussion started by: hindesite
2 Replies

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

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