Inserting text to a file with Sed within Bash Script

Posted by neversaint on Stack Overflow See other posts from Stack Overflow or by neversaint
Published on 2009-07-28T08:13:24Z Indexed on 2010/03/17 8:41 UTC
Read the original article Hit count: 408

Filed under:
|
|
|

I tried to insert a text to the first line of a file using sed. I do this inside a bash script.

But why it hangs at the line of sed execution?

#! /bin/bash

# Command to execute
# ./mybashcode.sh test.nbq

nbqfile=$1   
nbqbase=$(basename $nbqfile nbq)
taglistfiletemp="${nbqbase}taglist_temp"
taglistfile="${nbqbase}taglist"


./myccode $nbqfile | 
sort | 
uniq -c | 
awk '{print $2}' > $taglistfiletemp 

noftags=$(wc -l $taglistfiletemp | awk '{print $1}')
echo $noftags


# We want to append output of noftags
# to the first line of taglistfile

sed '1i\
$noftags' > $taglistfile

# why it hangs here
# the content of taglistfile is NIL

© Stack Overflow or respective owner

Related posts about bash

Related posts about sed