how can we write multiple lines to a text from command line without using cat, touch etc?
I was asked for an exercise and I would ofcourse like to learn how can this be done?
|
Quote:
And saying "etc" in this context rules out quite a bit, and you don't say what you're doing...for all we know, you have to write a program to do this, so doing it in C, Java, Perl, Python, etc., are all different and don't depend on cat, touch, 'etc'. |
we are working in linux bash.
we can't use cat, or touch, and I know its sth with echo I tried echo ''a'' \ ''b'' \ ''c'' > a.txt but it makes one line. I want to put a, b , c in different lines of the text. |
Suggest you try multiple lines in your script to echo to a file. Also look up the redirect which will create a new file versus the one which will append to an existing file. That will be important so that the first echo you can re-create the target file and subsequent echo lines you can concatenate to that file.
|
probably I didn't explain it well.
We want to write multiple lines at a text from command line without using cat, touch how can this be done? |
According to the man page for echo, you have half an answer that could be tried:-
Code:
echo -e 'a\nb' |
that works, thanks!
|
Does
Code:
echo -e a\nb |
no, it puts them in one line
|
Further, a standard shell takes a multi-line string.
Code:
echo "a Code:
echo 'a Code:
printf "%s\n" a b c |
we want to make it in one line command
|
Quote:
You opened a second thread to ask the same question, while you still haven't shown any effort thus far, even though you were asked to. Have you read the man page on the echo command, as you were advised to? Have you asked your instructor or looked in your textbooks? This is *YOUR HOMEWORK*...meaning it was given to you to learn and think about, not for us to answer for you. Suggest you look up redirects and pipes...any search engine will be able to give you a start. |
we join contents from many txt files in one using
more a.txt>c.txt ; more b.txt>>c.txt is it correct? |
Or even:-
Code:
rm c.txt; more *.txt >> c.txt |
Quote:
|
All times are GMT -5. The time now is 05:25 PM. |