|
|||||||
| 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
|
|||
|
|||
|
Hello All, I have following file contents Code:
cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line Code:
line=eeeeee and insert a new line Code:
line=ffffff immediate after this. I wrote following command to comment my line: Code:
sed 's/\(^line=*\)/#\1/' manish And Google for inserting a new line and found following solution: Code:
sed '/^line=/ a\ line=ffffff' manish
Output should look like: Code:
cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd #line=eeeeee line=ffffff #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! Thank you. Manish |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Try: Code:
sed 's/\(^line=.*\)/#\1\nline=ffffff/' manish |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
bartus11, Many thanks for your reply. It commented the required line but inserted the line in the commented line not in next line. Code:
sed 's/\(^line=.*\)/#\1\nline=ffffff/' manish #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd #line=eeeeeenline=ffffff #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! My requirment is to get line as: Code:
#line=eeeeee line=ffffff |
|
#4
|
||||
|
||||
|
Try this: Code:
perl -pe 's/^(line=.*)/#$1\nline=ffffff/' manish |
| The Following User Says Thank You to bartus11 For This Useful Post: | ||
manishdivs (12-17-2012) | ||
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
\n is not a standard sed feature in the replacement part of the substitute command. Try: Code:
sed 's/^line=.*/#&\ line=ffffff/' file Last edited by Scrutinizer; 12-17-2012 at 03:56 PM.. Reason: added trailing / |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
Code:
sed: 0602-404 Function s/^line=.*/#&\ line=ffffff cannot be parsed. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
Code:
sed 's/^line=.*/#&\ line=ffffff/' file |
| The Following User Says Thank You to Don Cragun For This Useful Post: | ||
manishdivs (12-17-2012) | ||
| 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 |
| script for inserting line at specific place in file | barrydocks | Shell Programming and Scripting | 9 | 02-10-2011 05:37 AM |
| Inserting a line in a file after every alternate line | appu2176 | Shell Programming and Scripting | 4 | 07-14-2010 10:07 AM |
| Problem inserting text into file after specific line | mocca | Shell Programming and Scripting | 0 | 03-15-2009 05:32 PM |
| Inserting a line before the line which matches the patter | laxmi131 | UNIX for Advanced & Expert Users | 10 | 12-18-2008 06:31 AM |
| inserting a line after a perticular line | uday610 | Shell Programming and Scripting | 2 | 10-19-2008 08:06 AM |
|
|