Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2009
Registered User
 

Join Date: May 2009
Posts: 28
Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line

something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong:

sed "2i\\${n}Category:$cat\n"

Sample:

Titel Blahh Blahh abllk sdhsd sjdhf
Blahh Blah Blahh
Blahh

Should look like this afterwards;

Titel Blahh Blahh abllk sdhsd sjdhf
Category:The Blahh
Blahh Blah Blahh
Blahh

2. Question: how should the syntax be, if the sed command itself should be a variable, like:

insertcat="sed "2i\\${n}Category:$cat\n""
Sponsored Links
  #2 (permalink)  
Old 05-20-2009
vidyadhar85's Avatar
Moderator(The Tutor)
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,459
you can use awk

Code:
awk '{if(NR==2){print "Category:"$0}{print $0}}' filename

  #3 (permalink)  
Old 05-20-2009
Registered User
 

Join Date: Sep 2006
Posts: 2,604

Code:
awk 'NR==2{print "Category:TheBlah\n"$0;next}1' file

Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
insert line into file using variable aimmanuel Shell Programming and Scripting 2 04-12-2009 12:30 PM
Return code of command assigned to variable browndr Shell Programming and Scripting 2 08-05-2008 09:26 AM
How to insert carriage return before line feed? huey ing Shell Programming and Scripting 2 08-05-2005 02:22 PM
Remove a carriage return at end of variable flagship99 UNIX for Dummies Questions & Answers 5 11-17-2004 06:39 PM
Regex to pick up name from the following including carriage return at end of the line Shakey21 Shell Programming and Scripting 3 07-18-2002 09:27 AM



All times are GMT -4. The time now is 06:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0