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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell script - reading line by line

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
Hello,

I'm just starting to use shell script so I'm probably approaching this wrong.

I'm referencing txt files in a directory then reading the file line by line and would like to save part of a specific line.
The line I'm interested in looks like:
Job Name = company:jobname

Here is the main section of the script:
Code:
for xfile in *.txt
do
   echo $xfile
   while read line
      do
         linetxt=$line
       # Look at the first 8 characters of the line
       # WORKS echo $linetxt|cut -c1-8

       # DOESN'T WORK extrtxt=$linetxt|cut -c1-8
       # echo $extrtxt

       # if [ '$extrtxt' = 'Job Name' ]; then
       #   echo $jobname
       # fi
   done < $xfile
#   mail -s "subject name" email@test.com < $xfile   
done

I'm trying to get it working in sections.
Ultimately I want the text to the right of the equal sign of the job name section to appear as the email subject.

How do I save the cut portion to a variable?

Thanks.

If at first you don't succeed, then sky diving wasn't meant for you!
 
I just found another reference and the first hurdle seems to be over come.

I needed to use:
Code:
extrtxt=`echo $linetxt|cut -c1-8`

If at first you don't succeed, then sky diving wasn't meant for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top