INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

shell script - reading line by line

shell script - reading line by line

(OP)
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:

Quote:


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!

RE: shell script - reading line by line

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close