New line being stripped from sed command


 
Thread Tools Search this Thread
Operating Systems SCO New line being stripped from sed command
# 1  
Old 03-22-2010
New line being stripped from sed command

Hi,

I am trying to insert text to the beginning of a text file with 'sed'. Its working however the new line is getting stripped.

I have a variable with the text that I want to insert:

VAR="This is the header line \n March 22, 2010 \n"
sed "1i\\
$VAR" logfile >tmpfile

The text gets inserted at the beginning of the file with no new line, just the 'n' with out the \.

# cat tmpfile
This is the header line n March 22, 2010 n

Is there a way to have the new line work here?

I am running on 5.0.7.

Thanks
# 2  
Old 03-22-2010
Code:
VAR="This is the header line 
March 22, 2010 
"

# 3  
Old 03-22-2010
This gives an error:

sed: Command garbled: March 22, 2010
# 4  
Old 03-22-2010
What's wrong with
Code:
echo $VAR >tmpfile
cat logfile >>tmpfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

Command line - awk, sed

My input file gfile values is CTRY=GM&PROJTYPE=SP&PROJECTTYPE=Small+Project If i am giving PROJECTTYPE then it must give Small Project awk -F"&" '{for (i=1; i<=NF; i++) if ($i ~ "^"PAT) {sub ("^"PAT"=", "", $i); sed 's/'+'/""/' $i ; print $i }}' PAT=$1 ... (6 Replies)
Discussion started by: nag_sathi
6 Replies

5. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

6. Shell Programming and Scripting

sed command to delete everything after > on line

I have a large data file that I need to edit. There are lines like, > <IDNUMBER> (ST000002) > <SUPPLIER> (ST000002) > <IDNUMBER> (ST000004) > <SUPPLIER> (ST000004) and I need to delete everything after the >, excepting the end of line. > <IDNUMBER> > <SUPPLIER> > <IDNUMBER> > ... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

7. Shell Programming and Scripting

sed command to delete line

HI, Im using the below commmand to delete lines having "(" at the start of a line. sed -e '/^(/d' But i need a command to delete lines that has only "(" in it and no other strings. infile - asdf asdf ( asdf ( asd outfile (1 Reply)
Discussion started by: dvah
1 Replies

8. UNIX for Dummies Questions & Answers

What is the command use to combine line using sed

Hi all, What is the sed command use to combine line? Example: Below is an output after extracted from few commands aaa bbb ccc ddd eee fff ggg and i would like to combine all the line as shown below, aaa,bbb,ccc,ddd,eee,fff (5 Replies)
Discussion started by: 793589
5 Replies

9. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

10. Shell Programming and Scripting

Need help in sed command [ printing a pattern + its line no or line no alone ]

Hello friends, Only very recently i started learning sed command...an i found that sed is faster in finding the patterns than some of my scripts that uses grep to check the patten inside a file using line by line search method which is time consuming. The below script... (4 Replies)
Discussion started by: frozensmilz
4 Replies
Login or Register to Ask a Question