0

I am trying to read each line of the file and then assign some parts of it to variables. A line itself is read as a variable so I need to process a variable input say for cat which seems to be impossible. I tried echoing but it looks like it doesn't do what I need.

This is how it looks like with cat:

cat $LINE | cut -f1

cat $LINE | cut -f4| sed s/\.pdf$/\.html/

Hopefully the problem has been put clearly enough. Any help would be greatly appreciated!

  • You may be mis-thinking this.  (Mis-thinking is a little like over-thinking, but misdirected.)  Read What is the XY problem?, and then tell us what you really want to do. – G-Man Says 'Reinstate Monica' Jun 15 '15 at 5:28
  • May be you were right but it didn't help me. Hope you can help me next time ;) – Jargal Jun 26 '15 at 1:10
  • X = "I am trying to read each line of the file and then assign some parts of it to variables."  Y = "A line is read as a variable so I need to process a variable ...".  OK, I'm sorry; you did tell us what you really wanted to do — or at least you hinted at it.  But then the last 90% of your question is cluttered with your flawed approach to doing it.  I hope that, next time you ask a question, you'll be able to tell us clearly what you really want to do, and focus your question on that.    :-|    ⁠ – G-Man Says 'Reinstate Monica' Jun 26 '15 at 9:09
0

cat takes a filename as its argument. You definitely need echo. What you may have wrong is that the line read will be space-separated, so cut needs a -d " ".

However, why not use the -r option of read ?

$ read -r NAME FNAME AGE FILE < file
$ echo $NAME
Doe
$ echo $FNAME
John
$ echo $AGE
36
$ echo $FILE
johns_letter.pdf
$ echo $FILE | sed -e "s/.pdf/.html/"
johns_letter.html
  • Thank you so much! You've helped me greatly when I was floating in the middle of desperation and panic making mistakes and not being able to see them :) the key thing was reading a line into variables. – Jargal Jun 26 '15 at 1:08
  • Glad to have helped. One SE way to say 'thank you' is to upvote and accept the answer! ;-) – Joce Jun 26 '15 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.