Remove # sign from the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove # sign from the file
# 1  
Old 02-05-2009
Remove # sign from the file

Hello Friends,

i need help to remove "#" sign from a file. I want to remove the "#" marks just in the area mentioned in red. I am not so good in awk, this help would be deeply appreciated.

thanks
Ado



trap = {
# {
# trap-community = SNMP-trap
# hosts = hubble, snowbell
# {
# enterprise = "sun"
# trap-num = 0, 1, 2-5, 6-16
# }

# {
# enterprise = "3Com"
# trap-num = 4
# }
# {
# enterprise = "snmp"
# trap-num = 0, 2, 5
# }
# }
# {
# trap-community = jerry-trap
# hosts = jerry, nanak, hubble
# {
# enterprise = "sun"3
# trap-num = 1, 3
# }
# {
# enterprise = "snmp"
# trap-num = 1-3
# }
# }
#}




Output should be like

trap = {
{
trap-community = SNMP-trap
hosts = hubble, snowbell
{
enterprise = "sun"
trap-num = 0, 1, 2-5, 6-16
}

# {
# enterprise = "3Com"
# trap-num = 4
# }
# {
# enterprise = "snmp"
# trap-num = 0, 2, 5
# }
}
# {
# trap-community = jerry-trap
# hosts = jerry, nanak, hubble
# {
# enterprise = "sun"3
# trap-num = 1, 3
# }
# {
# enterprise = "snmp"
# trap-num = 1-3
# }
# }
}

Last edited by asirohi; 02-05-2009 at 04:44 PM..
# 2  
Old 02-05-2009
sed -e 's/^# //' file_in > file_out
# 3  
Old 02-05-2009
this did not work, i just want to remove the # marks from the red area, not from the whole file.

Smilie
# 4  
Old 02-05-2009
Question

While I can see what you put in red, what is the rule to know what to remove the # character?
For instance,
lines 1-10, 20, 30
or
???
# 5  
Old 02-05-2009
I think to remove by line number(NR) would be okay. i just want to get the file to look like as i mentioned in the output.

thanks
# 6  
Old 02-05-2009
just a dumb question:

how do you know . ... which lines you want commented out?

apparantly you need this done during a batch program, that'll be
run many times, otherwise, just use vi and edit the thing....

If you know which lines need to be commented out based on
some criteria, then this is a rather difficult approach.

Can you do something like:
Code:
case $condition in

  A) this_trap_stuff ;;
  B) that_trap_stuff ;;
  C) even_more_other_trap_stuff ;;

esac

# 7  
Old 02-05-2009
Tools what about the following?

script execution
Code:
> play162.sh
trap = {
 {
 trap-community = SNMP-trap
 hosts = hubble, snowbell
 {
 enterprise = "sun"
 trap-num = 0, 1, 2-5, 6-16
 } 
# {
# enterprise = "3Com"
# trap-num = 4
# }
# {
# enterprise = "snmp"
# trap-num = 0, 2, 5
# }
 }
# {
# trap-community = jerry-trap
# hosts = jerry, nanak, hubble
# {
# enterprise = "sun"3
# trap-num = 1, 3
# }
# {
# enterprise = "snmp"
# trap-num = 1-3
# }
# }
}

script
Code:
> cat play162.sh

awk '
  { if (((NR>=2)&&(NR<=8)) ||
  (NR==17) || (NR==30)) {
    print substr($0,2,99)
  } else {
    print 
  }

}' file162

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Enter carriage return in xml file after each tag (> sign)

I have an xml file which is generated in a single line an looks like this <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Batch_Id="1999996" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><some data....><some data....>closing lines...... I need to have a separate line... (3 Replies)
Discussion started by: vx04
3 Replies

2. Shell Programming and Scripting

New to Perl Mail @ sign search and replace in a file

HI I'm terribly new to perl .. I;ve been trying to use this command to search and replace entries in a file I tried this and it works perl -p -i -e 's/old/new/' filename Problem is that I have a list of email addresses and I need to serach and replace the entire email address as my... (5 Replies)
Discussion started by: mnassiri
5 Replies

3. Linux

Linux command to find and replace occurance of more than two equal sign with "==" from XML file.

Please help me, wasted hrs:wall:, to find this soulution:- I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times) Examples 1. '===' 2. '====' 3. '=======' should be replaced by just '==' Note :- single character should be replaced. (=... (13 Replies)
Discussion started by: RedRocks!!
13 Replies

4. Shell Programming and Scripting

Shell not parsing $ sign from file

PFB my shell script which reads a csv file to process it ############################################### fn_java(){ echo JAVA_TOP is $JAVA_TOP echo "cp $filename $filepath/$filename" cp $filename $filepath/$filename } #########################################... (9 Replies)
Discussion started by: Prasannag87
9 Replies

5. Shell Programming and Scripting

how to get data from hex file using SED or AWK based on pattern sign

I have a binary (hex) file I need to parse to get some data which are encoded this way: .* b4 . . . 01 12 .* af .* 83 L1 x1 x2 xL 84 L2 y1 y2 yL By another words there is a stream of hexadecimal bytes (in my example separated by space for better readability). I need to get value stored in... (3 Replies)
Discussion started by: sameucho
3 Replies

6. Shell Programming and Scripting

Type ¥ yen sign in a terminal or a file

I'm trying to enter ¥ yen sign which is a part of a complex password in terminal putty thru bash shell how can i type such character in terminal or even write it in a file as a stdin for the client thanks ---------- Post updated at 05:38 PM ---------- Previous update was at 02:07 PM... (0 Replies)
Discussion started by: h@foorsa.biz
0 Replies

7. Shell Programming and Scripting

Parse file with '=' sign

Hi, Can anyone help me parse the code bellow. I have a file with several lines. I ant to put an 'X' on the lines that ONLY have an '=' in them ignoring comma's, spaces etc.. So: /* , systems.menuLabel.new=New systems.menuLabel.new.mnemonic=N */ Would look like: /* , ... (9 Replies)
Discussion started by: jascas
9 Replies

8. Shell Programming and Scripting

Sign on/Sign off logging script

I'd like to make a script that I can execute every time I sign on to my linux box that keeps track of the time and allows to me to add a remark to a file. So basically once I log in, I run the script, and it outputs the date and time to a text file (log.txt). But that isn't my problem. I need... (1 Reply)
Discussion started by: Glider
1 Replies

9. HP-UX

Replace $ sign within a file using Vi editor

Can someone help me with this command? I want to replace amount fields which are in the format $99.99 to 99.99 in a large data file which is within a HP box. I use Vi editor and tried this command :1,$s//$///g And this does not seem to work Also, I want to replace ^M with spaces in the... (1 Reply)
Discussion started by: dtonse
1 Replies

10. UNIX for Dummies Questions & Answers

remove pound sign from filename

Surpisingly, I've only found information regarding removal of files with special characters in the name. My problem is this: files are downloaded to my Unix box from mainframe, and each one has a pound sign as the first character of the filename. original: #FONT what I need: FONT ... (4 Replies)
Discussion started by: kristy
4 Replies
Login or Register to Ask a Question