|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sed to insert a character
Hi all, I have a file like this Code:
Q8N302 21-84 Q8N157 15-45 Q99996 167-201 202-251 269-318 I want to insert a character or space if the line starts with a number and I used the command Code:
sed 's/^[0-9]/#/' But in the output file, when it inserts this character, first digit in the number is deleted. How can I change the code so that I dont lose any digits. The output I am getting is given below Code:
Q8N302 #1-84 Q8N157 #5-45 Q99996 #67-201 #02-251 #69-318 #20-321 #22-323 |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Use '&' to insert matched string: Code:
sed 's/^[0-9]/#&/' |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
try also: Code:
sed '/^[0-9]/s/^/#/' |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| insert character in particular position. | Jairaj | Shell Programming and Scripting | 7 | 12-02-2010 08:48 AM |
| In Sed how can I replace starting from the 7th character to the 15th character. | mohullah | Shell Programming and Scripting | 5 | 09-22-2010 08:39 PM |
| Insert character in the line | swat | UNIX for Dummies Questions & Answers | 1 | 06-30-2009 11:12 AM |
| How to insert a character in line in Special condition? | bhaskar_m | Shell Programming and Scripting | 8 | 04-24-2009 08:45 AM |
| How can I insert character to end of file? | umen | UNIX for Dummies Questions & Answers | 1 | 01-29-2008 06:47 AM |
|
|