2

I got a problem to read standard input file, to edit the standard input, and to write the output to other file. So, the shell will be run with command like this:

./shellName < inputFile > outputFile

so I write my shell like this:

read INPUT
tr '[:upper:]' '[:lower:]' INPUT
grep "<td>" INPUT | sed -r 's/<td>([^<]*)<\/td>/\1/g' #to search all line that contain <td> and delete <td> and <\/td>
echo $INPUT

then, I just realize that the command read is read the standard input line by line. the code itself didn't work. I tried to change all uppercase to lowercase, and then delete and </td> on line that contain . What should I do? if I require to create an temp file, how can I create an temporary file in the shell?

1 Answer 1

1

It is actually much easier than you think. By default, tr reads from stdin (fd 0). The commands inside your script "inherit" stdin from the script unless you redirect it. So something like

#!/bin/sh
tr '[:upper:]' '[:lower:]' | sed -E 's/<td>([^<]*)<\/td>/\1/g'

I changed -r to -E as that is needed on my platform.

Sign up to request clarification or add additional context in comments.

2 Comments

wow. thx man. it works! btw what is -E? cant find it on the man page
On OS X it is the option to use extended regular expressions. The equivalent to the -r you used on linux (I just checked my linux box).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.