Friday 15 July 2011

shell - How to stream input line by line in UNIX, perform commands on each line, and immediately return output? -


I am trying to do something very easy, but by solving the way I want to solve it, I have many other commands Will also help with.

I want to read a file line from the line in UNIX and to command them, in this case, the character count for a complete file, I just use it: < Pre> wc -m

However, I want this input per line. What is the easiest, shortest way to streamline a file line from manipulation by UNIX Commands? I would ask because in this situation I want wc -m per line, but future applications will use completely different commands.

Besides, I want to avoid perl and awk! I already know how to do this with those devices, but I'm looking for alternative ways.

Thank you!

EDIT: Thank you for the link to the other question, but after looking for them 4 answers, I do not see the solution of my exact discrimination.

Looking at the following input:

  cat test.txt This is the first line, this is the second line, it is short This is my last line which is much higher than the first two rows   

I want to plug it through some code which will read a line from the line and execute an order on each line, will return the results immediately.

Some code that does wc -m on each line and outputs:

  23 32 14 65   

or some code that returns cut-d "" -f1 on each line and output:

  this is my   

Hope this makes things a little clearer thanks to any suggestions!

You know the length of the echo "$ {# line}" string for. Reading while reading the file ... The rest will work:

  $ cat file hello My name is the amount of federator while reading the line; Repeat "$ {# Line}"; Did & lt; File 5 7 8 3 0   

In a good format: line is echoed "$ {# line}" while reading & lt; File

No comments:

Post a Comment