text-formatting

Add two delimiters after every sixth comma

Add two delimiters after every sixth comma I’m trying to expand on this question but can’t figure out this issue: Let’s say I’ve got a file roll.txt: echo "’123456789′,’987651234′,’129873645′,’213456789′,’987612345′,’543216789′,’432156789′,’876543291′,’213465789′,’542637819′,’123456′,’23456′,’22234′,’3456′,’7890543′,’34567891,’2345′,’567’" >> roll.txt I can place a newline after every sixth comma with the following sed command: sed ‘s/,/,n/6; P; D’ roll.txt ‘123456789’,’987651234′,’129873645′,’213456789′,’987612345′,’543216789′, ‘432156789’,’876543291′,’213465789′,’542637819′,’123456′,’23456′, ‘22234’,’3456′,’7890543′,’34567891,’2345′,’567′ However, when …

Total answers: 5

fixing or finding an alternative to bad 'paste <(jcal) <(ccal)' output

fixing or finding an alternative to bad 'paste <(jcal) <(ccal)' output (I don’t have a high enough reputation to comment my question into: how to show stdout outputs of two programs side by side ) I’ve tried paste <(jcal) <(ccal) but the output is messed up. jcal; ccal; gives the correct output, just not side …

Total answers: 2

How to group matching data from first two column

How to group matching data from first two column I would like to group data from first two fields as per below Sample Data: CHECK|checkadm|block1 CHECK|checkadm|block2 CHECK|checkadm|block3 CHECK|checkadm|block4 TEST|testadm|block1 TEST|testadm|block2 TEST|testadm|block3 Final Output CHECK|checkadm|block1|block2|block3|block4 TEST|testadm|block1|block2|block3 Asked By: Rocky || Source What I would do, using array concatenation on each rows: awk ‘ BEGIN{FS="|"; OFS=""} {a[$1"|"$2]=a[$1"|"$2]"|"$NF} …

Total answers: 2

Joining multiple lines based on a regex

Joining multiple lines based on a regex I have the output of a pandoc conversion to HTML which looks like this: foo bar <blockquote> That’s one small step for man, one giant leap for mankind A new line and another quote </blockquote> baz I’d like to make it like this: foo bar<blockquote>That’s one small step …

Total answers: 3

Script to select a PulseAudio sink from an ordered list and use its name as command input

Script to select a PulseAudio sink from an ordered list and use its name as command input I wish to write a bash script that will create a PulseAudio loopback device between an audio source and a bluetooth device. (Context – skippable) The audio source is created with: load-module module-jackdbus-detect channels=2 sink_name=jack_bt_eq_out sink_client_name="PulseAudio – Bluetooth …

Total answers: 1

Visually aligning columns of a CSV file

Visually aligning columns of a CSV file Using sed or awk, is it possible to visually align columns in a CSV file? For example: e.g. from: a,b,c,some stuff,"some, other, stuff",d,2023-03-10 18:37:00 y,x,z,t,cool,thing,2022-04-12 21:44:00 to: a, b, c, some stuff,"some, other, stuff", d, 2023-03-10 18:37:00<EOL> x, y, z, t, cool, thing, 2022-04-12 21:44:00<EOL> There are some …

Total answers: 3

How to print leading zeros (padding) in awk?

How to print leading zeros (padding) in awk? I am trying to print 99.11111 as 099.11 in AWK. I have tried the following variations without success. $ awk ‘{printf ("%000.2fn", $1);}’ <<< 99.111111 99.11 $ awk ‘{printf ("%3.2fn", $1);}’ <<< 99.111111 99.11 $ awk ‘{printf ("%03.2fn", $1);}’ <<< 99.111111 99.11 Asked By: ychaouche || Source …

Total answers: 1

How to Replace Multiple Lines using Files on Termux

How to Replace Multiple Lines using Files on Termux Assume I have many *.txt files on directory texts with the below contents. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam tincidunt mauris eu risus. Vestibulum auctor dapibus neque. And I want to replace them with the following contents recursively. Vestibulum commodo felis quis tortor. …

Total answers: 2

How does awk print the columns in right-justify?

How does awk print the columns in right-justify? I have INPUT data like this: V 0.886 3.768 -2.882 C -0.082 3.768 -3.850 M -0.900 3.769 4.669 F -0.001 3.768 -3.769 I expect OUTPUT formatting like this: V 0.886 3.768 -2.882 C -0.082 3.768 -3.850 M -0.900 3.769 4.669 F -0.001 3.768 -3.769 I use this …

Total answers: 1

Writing bash arguments with trunctation

Writing bash arguments with trunctation I want to print the first two arguments of a bash function, with the unicode character u2263 on each side using a two space separation. The thing is that the final unicode must display at column 70. If the character region where $1 and $2 reaches column 68, the excess …

Total answers: 3

Arithmetic operation in terminal from an output

Arithmetic operation in terminal from an output I want to print the lines of updates via this command dnf check-update –refresh –q –downloadonly | wc -l However during the output there occurs a blank line which means the true update number is will be less than 1 from the output of the above command. How …

Total answers: 1

reformat numerical values to two values

reformat numerical values to two values I have a huge file with numerical values in many columns and rows. The values in the columns after column 6 are all numerical plus missing as NA (0 or 1 or 2 or NA). I would like to change values in all columns from column 7 and on …

Total answers: 1

insert block of lines only before first matched pattern

insert block of lines only before first matched pattern i need to insert the below lines (after variable substitution) before the first matched string which is server { in /etc/nginx/nginx.conf Variable: website=www.hello.com Block of lines: server { # Permanent redirect to www server_name ${website:4}; rewrite ^/(.*)$ http://$website/$1 permanent; } After variable substitution the block of …

Total answers: 2

Line up text based on line contents

Line up text based on line contents Is it possible to insert new lines in order to line up the contents of a file? I have: 1:1 Lorem ipsum dolor sit amet consectetur 1:1 This is sample text of varying length. adipiscing elit. 1:2 This is another paragraph in this file. 1:2 Vivamus integer non …

Total answers: 1

Indent lines of text following given rule

Indent lines of text following given rule I was wondering how indenting recursively more and more lines of poetry following a custom rule. For instance Let say we have: OF Mans First Disobedience, and the Fruit Of that Forbidden Tree, whose mortal tast Brought Death into the World, and all our woe, With loss of …

Total answers: 2

align data by word into column

align data by word into column How can I align data into pretty columns relative to given word? For example, I have output of the route -n command: default via 172.20.99.254 dev eth0 87.33.17.71 dev tun0 scope link 89.223.15.12 via 172.20.99.254 dev eth0 src 172.20.99.74 172.20.9.0/24 dev eth0 proto kernel scope link src 172.20.99.74 65.46.5.89 …

Total answers: 1

How to do formatted printing with jq?

How to do formatted printing with jq? jq has built-in ability to convert numbers to string or concatenate strings. How can I format strings inside jq similar to printf like padding (%4s). For example, how can I force number to occupy 10 char spaces with left alignment? echo ‘{"title" : "A sample name", "number" : …

Total answers: 3

POSIX equivalent to column -t

POSIX equivalent to column -t I was recently surprised to find out, that the POSIX list of utilities doesn’t include the column utility. column first appeared way back in 4.3BSD, and it’s is pretty useful. Is there a POSIX equivalent of it? The exact command I would like to replace is: $ more — ./tmp.txt …

Total answers: 3

How can I convert a text file to columns like a newspaper?

How can I convert a text file to columns like a newspaper? I don’t want to convert tabular data to nice columns like a standard awk recipe would produce. I want some text that’s very long to be formatted into columns like a newspaper column. For example turn Lorem ipsum dolor sit amet, consectetur adipiscing …

Total answers: 3

How do I convert a single column to 3 columns?

How do I convert a single column to 3 columns? I have large text file which contains data, formatted like this: 1 2 3 4 5 6 7 8 9 10 I am trying to convert it to this: 1 2 3 4 5 6 7 8 9 10 I tried awk: ‘{ if (NR%2) …

Total answers: 8