0

I wrote a shell script that reads from a fil

file="a.txt"
while read line
do

line1 = $(awk '{if($1 == "Only")print"$3;"}' "$line")
echo "$line1"
line1 = $(sed '$s/.$//' "$line1")
line2 = $(awk '{if($1 == "Only")print"$4";}' "$line")
line3 = $(sed -r 's/^.{3}//' "$line1line2")
done  <"$file"

I keep getting this error a.sh: 5: a.sh: line1: not found. What am I doing wrong ?

HackToHell
  • 1,941
  • 4
  • 27
  • 44

1 Answers1

4

No space allowed before and after the assignment operator. Change your code to:

line1=$(awk '{if($1 == "Only")print"$3;"}' "$line")
echo "$line1"
line1=$(sed '$s/.$//' "$line1")
line2=$(awk '{if($1 == "Only")print"$4";}' "$line")
line3=$(sed -r 's/^.{3}//' "$line1line2")

See Variable Assignment for more details.

Gergo Erdosi
  • 39,090
  • 21
  • 113
  • 91