Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

header

Status
Not open for further replies.

krava

Programmer
Jun 4, 2007
48
0
0
YU
hi,

I wrote a simple bash script:

putHeader(){
for fl in `find -name "$1"`; do
echo $fl;
tmpNm=$(basename $fl).tmp;
awk -v hd=$2 'BEGIN{print "hd"}' $fl > $tmpNm
#sed -e '1i \ $2' $fl > $tmpNm
rm $fl
mv $tmpNm $fl
done
}

I would like to put header into specified files like:

putHeader "*.dat" "energy errors"

Nither, awk not sed does not work. Could someone tell me why?
 
With awk :
Code:
putHeader(){
for fl in `find -name "$1"`; do
    echo $fl
    tmpNm=$(basename $fl).tmp
    awk -v hd="$2" 'BEGIN{print hd}' $fl > $fl.tmp
    mv $fl.tmp $fl
done
}

putHeader "tau*" "energy errors"


Jean-Pierre.
 
this deletes everything and put just the header
 
putHeader(){
for fl in `find -name "$1"`; do
echo $fl
awk -v hd="$2" 'BEGIN{print hd}[!]1[/!]' $fl > $fl.tmp && mv $fl.tmp $fl
done
}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top