Terminal: How to display vertical overflow in split view side-by-side - terminal

As it's quite exhausting to look at an ultra tall monitor (rotated ultrawide monitor) just to display long vertical output on a single screen,
I am wondering if there's a tiny program that could be fed the output of an arbitrary command via pipe and display vertical overflow on the right half of the terminal (while halfing the available terminal width reported to the program before the pipe).
So that
___________________
[AAA ]
[BBB ]
[CCC ]
^ultrawide-monitor^
___| |___
DDD <- vertical
EEE overflow
FFF
becomes
___________________
[AAA DDD ]
[BBB EEE ]
[CCC FFF ]
^ultrawide-monitor^
___| |___

Related

why does bash 'read' expand a wildcard appearing in stdin to yield a directory listing? [duplicate]

This question already has answers here:
I just assigned a variable, but echo $variable shows something else
(7 answers)
Closed 3 months ago.
I'm writing a script to process a data file, and started with these two command lines:
proc(){ echo $1 ; }
while read -r line ; do proc "$line"; done <data.csv | less
To my surprise, I found a listing of the current directory in the middle of the output, and realised it appears where the data file contains an asterisk character.
The expansion occurs before proc is called. Could someone please explain why this is happening. Is it happening in the command line processor or read or the file stream?
I can do this:
cat data.csv | tr '*' '_' | while read -r line ; do proc "$line"; done | less
but I'd like to know if there's a way to prevent this expansion.
Alternatively, is there a way to filter input using the redirection form, rather than the pipe, and what other special characters, eg: [,],?,- would I need to replace?
Cheers,
bitrat
PS: An example data file:
gfh fg hfgh fgh fg hgh
7 4 674 547767 56 7 56756
ghdghh gh fg h fgh fg hf gh
8 678 678 * 67 867 8 678
gfh fg hfgh fgh fg hgh
7 4 674 547767 56 7 56756
ghdghh gh fg h fgh fg hf gh
8 678 678 67 867 8 678
And example output:
gfh fg hfgh fgh fg hgh
7 4 674 547767 56 7 56756
ghdghh gh fg h fgh fg hf gh
8 678 678 data.csv file1.txt file2.txt file3.txt 67 867 8 678
gfh fg hfgh fgh fg hgh
7 4 674 547767 56 7 56756
ghdghh gh fg h fgh fg hf gh
8 678 678 67 867 8 678
UPDATE:
The asterisk is only treated as a wildcard if it has spaces on either side, so must be getting tokenised at some point.
UPDATE2:
The expansion doesn't occur if echo is called directly..
while read -r line ; do echo "$line"; done <data.csv
Why: Pathname expansion happens later than variable expansion. Search for "order of expansions" in man bash.
The expansion does not occur before proc is called, it happens inside proc.
Solution: Add double quotes:
echo "$1"

Increment digit in every matched column except first match [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have this sample file below. This file is in a size of 50 MB. I want to match "AAA 2A" and except the first line of the match I want to increment the number in second column. Below input file has 3 lines that contain "AAA 2A" so except the very first line I want to increment the digit in each second column by 1.
Input file
[root#localhost]# cat sample.txt
AAA 2A
BBB 4A
AAA 2A
BBB 1A
AAA 2A
AAA 3A
BBB 2A
AAA 4A
Expected Output
[root#localhost]# cat output.txt
AAA 2A
BBB 4A
AAA 3A
BBB 1A
AAA 4A
AAA 3A
BBB 2A
AAA 4A
awk 'BEGIN{counter=1}$0=="AAA 2A"{counter++;sub("2", counter)}1' <file>
counter starts at 1 and increases every time line is "AAA 2A". On those lines, it replace 2 with value of counter (so first time it gets it, value does not change because counter is at 2 already)

How can I compare two 2D-array files with bash?

I have two 2D-array files to read with bash.
What I want to do is extract the elements inside both files.
These two files contain different rows x columns such as:
file1.txt (nx7)
NO DESC ID TYPE W S GRADE
1 AAA 20 AD 100 100 E2
2 BBB C0 U 200 200 D
3 CCC 9G R 135 135 U1
4 DDD 9H Z 246 246 T1
5 EEE 9J R 789 789 U1
.
.
.
file2.txt (mx3)
DESC W S
AAA 100 100
CCC 135 135
EEE 789 789
.
.
.
Here is what I want to do:
Extract the element in DESC column of file2.txt then find the corresponding element in file1.txt.
Extract the W,S elements in such row of file2.txt then find the corresponding W,S elements in such row of file1.txt.
If [W1==W2 && S1==S2]; then echo "${DESC[colindex]} ok"; else echo "${DESC[colindex]} NG"
How can I read this kind of file as a 2D array with bash or is there any convenient way to do that?
bash does not support 2D arrays. You can simulate them by generating 1D array variables like array1, array2, and so on.
Assuming DESC is a key (i.e. has no duplicate values) and does not contain any spaces:
#!/bin/bash
# read data from file1
idx=0
while read -a data$idx; do
let idx++
done <file1.txt
# process data from file2
while read desc w2 s2; do
for ((i=0; i<idx; i++)); do
v="data$i[1]"
[ "$desc" = "${!v}" ] && {
w1="data$i[4]"
s1="data$i[5]"
if [ "$w2" = "${!w1}" -a "$s2" = "${!s1}" ]; then
echo "$desc ok"
else
echo "$desc NG"
fi
break
}
done
done <file2.txt
For brevity, optimizations such as taking advantage of sort order are left out.
If the files actually contain the header NO DESC ID TYPE ... then use tail -n +2 to discard it before processing.
A more elegant solution is also possible, which avoids reading the entire file in memory. This should only be relevant for really large files though.
If the rows order is not needed be preserved (can be sorted), maybe this is enough:
join -2 2 -o 1.1,1.2,1.3,2.5,2.6 <(tail -n +2 file2.txt|sort) <(tail -n +2 file1.txt|sort) |\
sed 's/^\([^ ]*\) \([^ ]*\) \([^ ]*\) \2 \3/\1 OK/' |\
sed '/ OK$/!s/\([^ ]*\) .*/\1 NG/'
For file1.txt
NO DESC ID TYPE W S GRADE
1 AAA 20 AD 100 100 E2
2 BBB C0 U 200 200 D
3 CCC 9G R 135 135 U1
4 DDD 9H Z 246 246 T1
5 EEE 9J R 789 789 U1
and file2.txt
DESC W S
AAA 000 100
CCC 135 135
EEE 789 000
FCK xxx 135
produces:
AAA NG
CCC OK
EEE NG
Explanation:
skip the header line in both files - tail +2
sort both files
join the needed columns from both files into one table like, in the result will appears only the lines what has common DESC field
like next:
AAA 000 100 100 100
CCC 135 135 135 135
EEE 789 000 789 789
in the lines, which have the same values in 2-4 and 3-5 columns, substitute every but 1st column with OK
in the remainder lines substitute the columns with NG

Command line to sum frequency in concatenated file

I need to summarize the frequency of one column of several large tab-separated files.
An example of the content in the file is :
Blue table 3
Blue chair 2
Big cat 1
Small cat 2
After concatenating the files, the trouble is the following:
Column 2 essentially is a frequency count of the amount of times the combination of Column 0 and Column 1 were seen together.
I need to add the frequency of all of the identical combinations in Column 2 of the concatenated file.
For instance: If in File A the contents are as follows:
Blue table 3
Blue chair 2
Big cat 1
Small cat 2
and in File B the contents are as follows:
Blue table 3
Blue chair 2
Big cat 1
Small cat 2
the contents in the concatenated File C are as follows:
Blue table 3
Blue chair 2
Big cat 1
Small cat 2
Blue table 3
Blue chair 2
Big cat 1
Small cat 2
I want to sum the frequencies of all identical combos in Column 0 and Column 1 in a File D to get the following results:
Blue table 6
Blue chair 4
Big cat 2
Small cat 4
I tried to sort and count the info with the following command:
sort <input_file> | uniq -c <output_file>
but the result is the following:
2 Big cat 1
2 Blue chair 2
2 Blue table 3
2 Small cat 2
Does anyone have a suggestion of a terminal command that can produce my desired results?
Thank you in advance for any help.
You're close; you have all the numbers you need. The total for each row is the count of rows that you got from uniq (column 1) times the frequency count (column 4). You can calculate that with awk:
sort input.txt | uniq -c | awk ' { print $2 "\t" $3 "\t" $1*$4 } '

Oracle reports center aligning the header of a field in a repeating frame

I have a label and a field as in the follwing layout.
________________
| _____ |
| | | |
| |Label| |
| |_____| |
| |
| ____________ |->Outer fixedframe
| | _______ | |
| | | | | |
| | |field| | |
| | |_____| | |
| |__>_______| |
| | |
| -->Inner |
| Horizontally expanding repeating frame
|______________|
I would like to center align the label with respect to the field in the inner repeating frame. For example,
If the repeating frame generates 5 fields, the label needs to be right above the 3rd field.
Is this possible using oracle reports or any alternate layouts?. Any help would be much appreciated
I just got this working with a quick mock-up and here is how I did it:
1) Select the "Anchor" tool from the tool palette and anchor the bottom middle "outline square" (I'm not sure what the technical term for those are but the grab-points on an object where you can resize them) from the label object and connect it to the top middle "outline square" of the horizontal repeating frame.
2) [Optional] Click on the anchor line and check the properties to make sure the Child Edge Type is set to "Bottom", the Child Edge Percent is "50", the Parent Edge Type is "Top", and the Parent Edge Percent is "50".
3) Click on the label and set the Keep With Anchoring Object property to "Yes".
4) Make sure your label is centered over the repeating frame in the Paper Layout view. I noticed that if it is off-centered to start with it will be off-centered by the same amount when run. I ended up making the label the same width as the repeating frame it was over and then set both to a Horizontal Elasticity of "Variable".
I ran this with 5 horizontally repeated objects and then I added a 6th to verify it remained centered and both worked.
Hope that helps and that I didn't miss a step. I'll save the mock-up in case it needs further steps or explanation.

Resources