I'm having issues wrapping my brain around how to accomplish this.
Basically, as I go through a text document I have I get a comma separated line where there are two attributes then an image name. The next couple lines lack the two attributes but contain different image names. To the software I'm working with, these additional image named lines without the two attributes are related to the first line WITH the attributes. I would like to take the two attributes and assign them to the next lines that lack them... The number of images per "group" varies. It looks like this:
red, large, kitty1235.jpg
,, kitty1294.jpg
,, kitty3452.jpg
orange, small, cuteface123.jpg
,,adorable544.jpg
...and what I am trying to do is:
red, large, kitty1235.jpg
red, large, kitty1294.jpg
red, large, kitty3452.jpg
orange, small, cuteface123.jpg
orange, small, adorable544.jpg
I know there has to be a way, I'm guessing I'm going to have to use an array but I'm a newb at that. Any help would be GRAND.
Thanks!
Here is the awk solution, which could be easily adjusted to virtually any language. It takes line by line, remembers the values of the first and second fields, and uses them if the fields are empty:
> awk -F, 'BEGIN {f1="";f2="";OFS=", "} {if ($1=="") $1=f1; if ($2=="") $2=f2; f1=$1;f2=$2; print}' x.txt
red, large, kitty1235.jpg
red, large, kitty1294.jpg
red, large, kitty3452.jpg
orange, small, cuteface123.jpg
orange, small, adorable544.jpg
Related
Within an Ace editor, it is easy to find the number of lines in the edited document with the following:
myEditor.session.getLength();
But languages like JSON or XML can be "folded." That is, children properties or elements can be collapsed so only one single line is displayed for the parent.
Is there a way to get the number of lines actually displayed? Something like the following:
myEditor.session.getVisibleLength();
Note: the ultimate goal is to have an editor that adapts its height on the page to the content it displays (if lines are collapsed, then it should shrink, and if collapsed lines are expanded again, it should increase its height.)
UPDATE: After a user's response, I use the following. This is not the answer to the specific question I asked above, but rather the perfect answer to what I was trying to achieve overall:
const myEditor = ace.edit(elem, {minLines: 5, maxLines: 50});
To automatically change the height of the editor use maxLines option, but don't set it to a very large value as performance depends on the number of displayed lines.
Im not sure how to express it so I posted a picture in link below.
It should look like this
Just enter the text on 3 lines like so:
MORE
AT
THE HALL
Then adjust the point sizes, leading, kearning, etc. to create the aesthetic you want.
In this case line 1 and 3 could have full justification.
You can use scaling of the text(as shown in the character panel in attached snapshot) because changing font size also moves the baseline and causes the text to shift downward.
These attributes are also exposed via scripting.
I have a label stock that has two labels side by side, so I've written my code to print identically on both of these labels.
The issue is that a printer sees this as one label, but I need it to see them as two. How then, could I possibly trick the printer into thinking two labels have been printed?
If ZPL can print 2 separate pieces of code on one label this might be possible. If there's a command that makes a single label count as 2 then it's definitely possible.
I am trying to colorize text. Say I want blue text. This is the way I get it:
"\e[34mThis is blue text.\e[0m"
I am using define_method to create multiple methods (one for each color). I keep the color code for each color in an array. I iterate over both the color array and the color code, and do this:
"\e#{code}m[#{self}\e[0m"
When I run it, I get "m[test" instead of the colorized text.
Any thoughts? If, instead of #{code}, I put the actual code, it works, but that'd be like 20 ifs, one for each color, and it won't be DRY.
You are likely a victim of copy-paste :)
# ⇓ incorrect
puts "\e#{code}m[#{self}\e[0m"
# ⇓ correct
puts "\e[#{code}m#{self}\e[0m"
The opening square bracket should follow \e, not m.
I am trying to achieve multi colored text with the colored gem in ruby.
Basically I want to set a base color for the text, but highlight specific details in another color while still keeping all the other text in the base color.
For example if I do something like:
puts "Found #{book_title.yellow} and it has #{chapters.to_s.yellow} chapters".green
I would of expected that the entire phrase would be green except for the book title and number of chapters which should be yellow.
Instead the results are that "Found" is green, book title is yellow, "and it has" is white (no color), chapters is yellow, and "chapters" is white (no color).
It simply appears that appending .green to the surrounding string doesn't re-add the color codes after a color change when using #{} to insert data.
I want to build this functionality into a info function like so:
def info(message)
time_stamp = "[#{Time.new.strftime("%H:%M:%S")}]"
puts "#{time_stamp} Info: #{message}".green
end
So that when I call it like so:
info "Found #{book_title.yellow} and it has #{chapters.to_s.yellow} chapters"
It will print the entire statement in green with highlighted text in yellow as described above.
Is this possible without breaking the string into substrings and concatting them, or specifying a hard coded list of arguments to the info function (the number of highlighted texts is dynamic). Is there a VA_LIST type like in C's printf I could use?
I wouldn't mind calling the function as:
info "Found %s and it has %d chapters", book_title.yellow, chapters.to_s.yellow
or something similar. But I would still need to figure out a way to set the color codes for each segment of text and concat them together.
Hopefully this makes sense.