ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The read command reads one line of text. Is there a builtin command to write lines? prinf write a line and I can use an empty format string. But it realy writes FORMATTED lines. In C there is puts, and all the other puts besides printf. So may be in bash there is something like it.
#!/bin/sh
while read line ;
do
echo $line
done<foo >jose
If for each line that is read I want to output it, how do I do? Modifying the echo line, that is 'echo $line > some_file won't do.
Code:
cp foo jose
Jokes aside, do you want to append every single line read inside the while cycle to the same output file? You should use the ">>" operator instead of the ">", which overwrites every time the output file.
Jokes aside, do you want to append every single line read inside the while cycle to the same output file? You should use the ">>" operator instead of the ">", which overwrites every time the output file.
Its only a skeleton for aa larger script. And is it possible to locate a given substring within line with only buitins? And with an external command?
Is PERFORMER the literal substring you're searching in every line?
If so:
Code:
case $line in
*PERFORMER*)
continue
;;
*)
echo $line
;;
esac
The patterns you can specify in a case statement (those before the 'close bracket' ')') can use wildcards such as * (0 or more characters) or ? (0 or 1 character) or + (1 or more characters).
In this case, we first look if $line contains PERFORMER in a non-specified position (* before and after it means that there can be 0 or more chars before and after it) and, if so, we continue.
If there was no match with the first pattern, than case tries to match $line with the second one (which matches everything) and proceeds to echo the line.
Hope this is clear enough to understand.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.