How to remove the # char form a line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove the # char form a line?
# 1  
Old 01-02-2013
How to remove the # char form a line?

Hi,

my file has below details and I want remove the # char from only specific line.

Code:
#TEST:00:START
#TEST1:01:INPROCESS
#TEST2:02:ABOUTTO
#TEST3:03:COMP

i.e if want remove the # from 2nd line then file to be updated as

Code:
#TEST:00:START
TEST1:01:INPROCESS
#TEST2:02:ABOUTTO
#TEST3:03:COMP

please provide the script to do this.

Thanks,
Sandy

Last edited by Scrutinizer; 01-03-2013 at 03:15 AM.. Reason: code tags
# 2  
Old 01-03-2013
try:
Code:
awk 'NR==2 {sub("^#","")} 1' infile

or:
Code:
sed '2{s/^#//}' infile

# 3  
Old 01-03-2013
Code:
sed '2s/^#//' infile

--
@rdrxt1, some seds require a semicolon before the closing brace.
# 4  
Old 01-03-2013
And if you like to program the line to remove
Code:
line=2
awk 'NR==inp {sub("^#","")} 1' inp=line infile

# 5  
Old 01-03-2013
Thanks quick solutions.

if the line number is unknow, will it be posible to update based on the content means TEST or TEST1?
# 6  
Old 01-03-2013
Try:
Code:
sed '/TEST1:/s/^#//' file

# 7  
Old 01-03-2013
Code:
awk '/TEST1:/ {sub("^#","")} 1' infile
awk '/TEST:/ {sub("^#","")} 1' infile

The : is needed so that it selects only TEST and not TEST1 and TEST when search for TEST
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove char if not a number

I need to write a BASH script that takes a 2 character string and removes the second character if it is not a digit e.g. If the string is numberical value >9 e.g. string1 = '34' then leave string1 = '34'. However if the string is <10 e.g. string1 = '3X' then remove the second char (which... (7 Replies)
Discussion started by: millsy5
7 Replies

2. Shell Programming and Scripting

Remove only specific char on every line when exists

Hi I need to remove "|" char when it's the last char of the line. Input file: generoso|desprendido|altruista| abnegar|ceder|sacrificar| abocetado-da|esbozado| apuntado|insinuado|incompleto abocetar|esbozar|bosquejar| diseņar|delinear ------------------------ output need --- ... (11 Replies)
Discussion started by: lookoo
11 Replies

3. Shell Programming and Scripting

Remove x lines form top and y lines form bottom using AWK?

How to remove x lines form top and y lines form bottom. This works, but like awk only cat file | head -n-y | awk 'NR>(x-1)' so remove last 3 lines and 5 firstcat file | head -n-3 | awk 'NR>4' (5 Replies)
Discussion started by: Jotne
5 Replies

4. Shell Programming and Scripting

Copy last third char form string

HI Input A.txt ABC907 ABC907_1B_9 ABC985 ABC985_1A_9 ABC985 ABC985_1B_9 ABC985 ABC985_1C_9 ABC05037 ABC05037_1A_9 ABC05037 ABC05037_1B_9 Base of column 2 last third char. If It is A the 1,if B then 2 If C then 3 File B.txt ABC907 ABC907_1B_9 2 ABC985 ABC985_1A_9 1 ABC985... (8 Replies)
Discussion started by: asavaliya
8 Replies

5. UNIX Desktop Questions & Answers

Help me to remove junk char

I wanted to remove junk char in my csv. :mad: Input file format: "17","9986782190","0","D","2" "17","9900918331","0","D","2" "13","9986782194","0","A","2" Output file format 9986782190 9900918331 9986782194 And one more thing all the time "13"," this will be different Ex: . (2 Replies)
Discussion started by: Siddartha
2 Replies

6. UNIX for Dummies Questions & Answers

Remove First Char from Line in File Only if it's a comma

I have a file, I need to remove the first character of each line, but only if it's a comma. I don't want to delete any other commas in each line. Trying cat or sed but I really don't know them very well, would love some help. This removes the first comma, but it removes the first comma no... (6 Replies)
Discussion started by: Cynthia
6 Replies

7. Shell Programming and Scripting

Remove char after Colon

Hi guys, This is my input 2735:<7001> 34 789 701 2 2774:<7001> 34 789 701 2 How to delete characters after colon : Including colon : too ? My output should... (3 Replies)
Discussion started by: gowrishankar05
3 Replies

8. Shell Programming and Scripting

can I remove the first char using AWK?

Hi everyone, suppose that I have the following line: #test your knowledge can I use AWK to print the word "test" only? without the #? what should I change to this: awk '{print $1}' thanks in advance guys (2 Replies)
Discussion started by: Abdulelah
2 Replies

9. Shell Programming and Scripting

how first char in odd line and second char in even line

Hi I m having ifconfig -a o/p like sbanlab1:ksh# ifconfig -a | egrep "flags|inet" | awk -F' ' '{print $1,$2}' lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 bge0:... (1 Reply)
Discussion started by: tarunn.dubeyy
1 Replies

10. Shell Programming and Scripting

How to remove new line char from a string

Hi Can anyone tell me how can i remove new line character from a string. My requirement is to read a line from a file and store it to a string. read line string1=$line read line string2=$line echo $string1$string2 The result i am getting in different line. i want the output in the same... (1 Reply)
Discussion started by: sreedivia
1 Replies
Login or Register to Ask a Question