Shell Script - Cant get sed to replace a line from a textfile
Hi all,
Below is a script to parse IOS crash logs. What I wanted to do, was take in the file process the command, then replace the lines that have our appname in them. Currently the output, looks identical to the original file. I think the sed line is the issue (woof=`echo $tempFile | sed `$cmd``). Any help would be greatly appreciated. Banging my head against the desk at the moment.
#! /bin/bash
APPNAME=$1
FILENAME=$2
BUGNAME=$3
echo APPNAME IS $APPNAME
echo FILENAME IS $FILENAME
contentsOfFile=`cat $FILENAME`
tempfile=$contentsOfFile
echo $tempfile
for i in `grep -n $APPNAME $FILENAME | grep [1-9]* | awk '{print $1 "," $2 "," $3 "," $4 "," $5 "," $6}'`
do
myline=$i
linenumber=`echo $myline | cut -d':' -f 1`
echo linenumber: $linenumber
hexaddr=`echo $myline | cut -d',' -f 3`
echo $hexaddr
if [[ -n "$hexaddr" ]]
then
atosResult=$(atos -arch armv7 -o $APPNAME".app/$APPNAME" $hexaddr)
else
hexaddr=0x00000
#atosResult=$(atos -arch armv7 -o $APPNAME".app/$APPNAME" $hexaddr)
fi
sedCommand=$linenumber's'
echo $sedCommand
echo Atos command before sed: $atosResult
atosResult=`echo $atosResult | sed "s/'//"`
echo Atos command after sed: $atosResult
cmd="$sedCommand/.*/$atosResult/"
echo CMD:$cmd
woof=`echo $tempFile | sed `$cmd``
echo Woof: $woof
done
for f in "${tempfile[@]}"
do
echo "Processing $f file..."
echo >>"$OUTPUT"
while IFS='' read -r line; do
printf "%s\n" "$line">>"$OUTPUT"
done <"$f"
echo >>"$OUTPUT"
echo >>"$OUTPUT"
done
echo "$tempfile" > $BUGNAME
Edited: It seems to be a problem with the atos command and what it returns. This has [ brackets - dashes and * in the text. See my post below for an example. I need a way to in line of text replace a line with the atos result. Thanks all.
Last edited by CrowdstarQA; 02-23-2012 at 12:00 PM.
|