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.
Do you really want them merged with no spaces or punctuation?
Regardless, SED will do it. Go here and read up on SED: http://www.grymoire.com/Unix/Sed.html
Basically, the approach is to read a line into the working register, move to the hold register, and then get the next line and test it for "+". If it does NOT have +, then append it to the hold register. When you come to the next line starting with +, then switch it with the hold register (which now contains all the previous lines), remove the newlines, and then print the combination line.
This seems like it might be homework---but regardless, tell us more about what commands and utilities you are familiar with.
input=File.txt
while
read line
do
if [[ $line = *'+'* ]];
then
echo $line >> NewFile.txt
elif [[ $linha != *'+'* ]]; then
echo $line | tr -d '\n' >> NewFile.txt
fi
done < $input
@ amboxer21 - the trick here is that we are not assigning anything prior to the '?'. As a combination, ?:, is equivalent to a shortened form of and if/else. Everything after '=' and prior to '?'
is an expression to be tested and when true it will return the portion between '?' and ':', and when false it will return the portion after ':'.
So:
ORS = " ", when NR % 4 is any non-zero value, ie anything not exactly divisible by 4
ORS = "\n", when the above is false, ie. NR == 4 or 8 or 12 ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.