Questions tagged [text-formatting]

Questions about using command-line utilities such as awk, sed, perl, pr, etc. to format text files. For printf format strings, use the [printf] tag. For date format strings, [date]. See also the [text-processing] tag.

Filter by
Sorted by
Tagged with
0 votes
0 answers
52 views

Text processing grep and awk together on live script not working

I am using ssh to login to a remote server (Ubuntu), and then issue a command which outputs text/value each sec (live script). In the live output, I want to filter out the lines containing '...
SAM's user avatar
  • 1
0 votes
2 answers
40 views

process a text file to modify a column value based on maximum value from another column

I have a file that i am looking to modify. There are 100's of files having the same issue. the input file is below sample1 100A total 1 1000 sample2 100A total 1 5584 sample3 100A ...
bioiinffun's user avatar
1 vote
2 answers
66 views

Reformat text to exact width [duplicate]

On Ubuntu, how to reformat text to fit width (except final line), adding spaces where necessary? The closest I can get is with fmt --width=64, but this does not add the spaces between words. Input ...
FromTheStackAndBack's user avatar
1 vote
1 answer
23 views

How do I format the output of cut to the following format? [duplicate]

last part of the command: | cut -d' ' -f3 output: 4 10 required format: 4,10 I'm guessing echo (and sort?) is to be used in some way, but I can't quite place my finger on it.
kesarling He-Him's user avatar
2 votes
1 answer
44 views

text formatter that supports bullets

I am looking for a formatter to use with my git commits. par pretty much does what I want, with the (important) limitation that I can't get it to properly format bullet lists, which are pretty common ...
m000's user avatar
  • 181
0 votes
0 answers
65 views

Find and replace in CudaText editor

So I have dump from U-boot and I need to replace specific string in CudaText editor. Here is mine text e101b1e0: 30ef27d8 e792f415 9beea618 5c601de4 .'.0..........`\ e101b1f0: aeaf9d25 e1dd63e9 ...
Slobodan Vidovic's user avatar
-3 votes
1 answer
161 views

Template for formatting output as a dynamic table in bash

I have a created a simple script which is using the ps aux command to give information for a process entered by a user, and presents the output in a table like format (something like the mysql shell ...
October's user avatar
2 votes
0 answers
37 views

Generate upper-case in a udev rule?

I have a use case with cross-platform context which makes me want to generate symlinks under a /dev/disk/by-X directory that have an uppercase version of data returned by blkid. Is there a built-in ...
RJVB's user avatar
  • 254
1 vote
1 answer
60 views

Sed - replace a string with a character of another line

I am trying to write a script to reformat some text. pages: page1: gui-rows: 6 items: '6': material: CAT_SPAWN_EGG buy: 999999999 sell: -1 '7': ...
Pegoku's user avatar
  • 11
3 votes
5 answers
741 views

How can I reformat blocks of data until the end of the file is reached?

I have a file that looks like this: # Time-averaged data for fix avetimeall # TimeStep Number-of-rows # Row c_gyrationchunkall 1000 3 1 2.09024e-14 2 4.88628 3 5.69321 2000 3 1 2.10518e-14 2 8.33702 3 ...
Felipe Evaristo's user avatar
1 vote
1 answer
82 views

How to preprocess output of any CLI Tool in realtime?

For context, what I am trying to do is add a preprocessor to a REPL, more specifically, nix repl. Although this would probably apply to any other REPL like application. The reason for it is that I ...
Mathias Sven's user avatar
1 vote
5 answers
131 views

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'...
jophuh's user avatar
  • 13
1 vote
2 answers
175 views

Recursive pattern search - output formating: for each match file print out the specific file name "\n", line number, sentence matched "\n" in colors

I want a file content search command, under Linux so that: it will search on specified files, e.g: md, txt, htm. recursively from the folder and its subfolders, e.g: . the content search can be ...
user2718593's user avatar
0 votes
0 answers
55 views

Date format in /var/log/cron (Oracle Linux Server 8.8)

Currently the date format in /var/log/cron seems to be %b %d %H:%M:%S, so in /var/log/cron I see the logs like Aug 20 03:13:01 bhost1 CROND[1361808]: (user1) CMD (......) Is it possible to change the ...
StefanG's user avatar
  • 101
0 votes
0 answers
66 views

How can I parse the output of w to collect current user sessions?

I want to parse the output of w so I can collect current user sessions and record them via telegraf. However, it only provides space separated output and I'm not sure how to reliably parse this ...
Zac Pullar-Strecker's user avatar
3 votes
2 answers
82 views

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; ...
YQ002lc2's user avatar
1 vote
2 answers
54 views

Change irregular header with extra whitespace

I am working with data in this obscure file format: SNP A1 A2 F1 I1 F2 I2 F3 I3 rs0001 A C 0.02 0.00 1.99 (Note the whitespace around the first three fields) The header is long (500k ...
Giulio Centorame's user avatar
-2 votes
2 answers
59 views

How to group matching data from first two column [closed]

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|...
Rocky's user avatar
  • 3
-1 votes
3 answers
123 views

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 </...
Josh Friedlander's user avatar
1 vote
1 answer
58 views

"par" formatter does not retain tab indentation

I'm writing code in Vi and using the par text formatter (similar to fmt, but IMHO better) to format block comments. The issue is that I can't get par to keep the literal tabs I use for indentation. ...
Kusalananda's user avatar
  • 335k
3 votes
2 answers
934 views

How can I pretty-print or beautify GraphQL text from the command line?

I have a GraphQL query in GetPerson.gql that is all scrunched up on a single line: { getPerson(id: 42) { name, age } } How can I pretty-print or beautify this text using the command line? $ magical-...
Cory Klein's user avatar
  • 18.9k
1 vote
1 answer
218 views

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) So far I have (the relevant part of) my script as: ...
Marc.2377's user avatar
  • 1,112
1 vote
1 answer
203 views

pretty-print css one-liner

I (human) would like to read this ~30000 chars long line of CSS. @font-face{font-family:KaTeX_Script;src:url(/static/fonts/KaTeX_Script-Regular.af7bc98.woff2) format("woff2"),url(/static/...
Poor Standard's user avatar
4 votes
3 answers
1k views

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:...
s.k's user avatar
  • 461
3 votes
1 answer
1k views

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.2f\n", $1);}' <<< 99.111111 99.11 $ awk '{printf ("%...
ychaouche's user avatar
  • 998
-1 votes
1 answer
60 views

How can I format the output of a shell command into columns, but limit the number of columns created?

Say I run systemctl | grep running | column -t I get an output that looks like this: init.scope loaded active running System and Service Manager session-...
DrKumar's user avatar
  • 119
3 votes
2 answers
264 views

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. ...
zakadmin's user avatar
3 votes
2 answers
164 views

Indent Fortran source code, propagate indentation down to unindented special lines

I'm trying to write my own script to improve some auto-formatting before commiting to a remote repository. I use indenting guides in my IDE and the autoformatters available for my language (FORTRAN) ...
Philip Moloney's user avatar
2 votes
1 answer
1k views

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 ...
Binh Thien's user avatar
1 vote
3 answers
80 views

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. ...
Vera's user avatar
  • 1,223
0 votes
3 answers
74 views

Add custom delimiter in key-value pair

I have data which are in "Key:value" form (901 S 902 M 905 F 906 WAPENC 907 31 908 371 909 38765469947/TYPE=PLMN and so on ) where keys are 901,902,905,906.....so on and respective values ...
Sunny's user avatar
  • 23
2 votes
2 answers
125 views

Add custom delimiter in key-value form data

I have data which are in "Key:value" form where keys are 901,902,903,904 and respective values are S,M,F,WAP`, with space as delimiter. Input example 901 S 902 M 903 F 904 WAP ..... I want ...
Sunny's user avatar
  • 23
0 votes
2 answers
181 views

How to echo a string inside a category in a ini file with quotes

I have an ini file like for example [Admin Prefixes] # Here you can add custom prefixes to specific players or flags that are shown when using $admin_prefix$. # Syntax: "type" "info&...
ph3ro's user avatar
  • 378
0 votes
2 answers
295 views

convert xterm256 to ansi

I have a program that will only accept ANSI color input but I have reason to feed it the output of a program that outputs xterm256 color codes. Is there a converter? I realize of course that color ...
Ray Andrews's user avatar
  • 2,381
2 votes
1 answer
118 views

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 ...
Neptune's user avatar
  • 153
0 votes
1 answer
136 views

highlight command refuses to change theme

$ highlight -l -s clarity -S sh -O ansi some_file No matter what I try, highlight always shows the same theme. And it is supposed to create a file 'highlight.css' but it doesn't. What am I doing ...
Ray Andrews's user avatar
  • 2,381
1 vote
3 answers
246 views

text processing rows to columns for a block of lines Awk

i have input file like below .i need to reformat the text as o/p mentioned. I using the awk got from this forum but it is displayed based on the List A columns count. Please help awk 'BEGIN{ max=0 } ...
Renga's user avatar
  • 393
0 votes
1 answer
75 views

How to follow logs while avoiding line wrapping w/ horizontal scroll enabled?

In the terminal, if I don't want to have logs of a program wrap, I can pipe those to less -S. However, horizontal scroll with keyboard doesn't work unless I Ctrl+C, and after that, I don't know how to ...
doplumi's user avatar
  • 101
0 votes
1 answer
36 views

Split lines (like fmt -w) but on coloured / formatted command line output

I have output from a command (jest, for running automated JS tests) that uses fancy terminal codes to do things like coloured text in its output. I want to trim any very long lines because I run jest ...
Croad Langshan's user avatar
1 vote
2 answers
54 views

Transpose with row condition

Need help in formatting below test data in unix. Sample data: Dan serv1 p1 Dan serv2 p2 Dan serv3 p3 Dus serv2 p1 Dus serv3 p2 Dus Serv5 p3 Tes serv3 p1 Tes serv5 p3 Needed format: Name p1 p2 ...
Abi's user avatar
  • 19
2 votes
2 answers
307 views

Remove empty lines in tab delimited file while preserving row labels

I have a tab delimited file with column headers like ID, A, B, C, D as shown in the pic below, and row labels too like a, b, c, d, e show below in pic. How do I remove all the empty lines (rows) while ...
Ben M's user avatar
  • 21
-2 votes
1 answer
47 views

reformat numerical values to two values [closed]

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 ...
motor 30's user avatar
2 votes
2 answers
172 views

awk to change any values except 0,1, 2 to missing (NA)

I have a huge file with numerical values in many columns and rows. The values for columns are all numerical and 98% are [0 or 1 and 2]; However for some these are beyond 0,1 and 2, for example 1....
motor 30's user avatar
1 vote
3 answers
852 views

Insert character in middle of string

I would like to perform adding hyphen "-" character in my string. How would like to perform? vol0802-f522-6cc63-0a3-d I am getting the above about output. However, I need the following ...
Sandeep K's user avatar
0 votes
4 answers
64 views

Convert abc pqrs xyz on separate lines into 'abc','pqrs','xyz' on a single line, using awk

printf 'abc\npqrs\nxyz\n' | awk $'{ print "\'" $0 "\'" ,sep="," ,ORS=""}' Output: 'abc' , 'pqrs' , 'xyz' , expected output: remove last/ end of the comma(,) ...
user540652's user avatar
0 votes
2 answers
225 views

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 { # ...
Ashar's user avatar
  • 491
3 votes
6 answers
983 views

Splitting columns in TSV into CSV

I have a TSV file with two columns in the format of id1\tcol1,col2,col3 id2\tcol4,col5 I want to split the second column in combination with the first column to output id1,col1 id1,col2 id1,col3 id2,...
Googlebot's user avatar
  • 1,959
0 votes
2 answers
410 views

Add commas in place of number with sed?

Trying to write a simple script to fetch ethereum price and format the response. Here is what I've tried: #!/bin/bash response=$(curl 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=...
ash's user avatar
  • 1
0 votes
1 answer
75 views

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 ...
Venem's user avatar
  • 11
0 votes
1 answer
57 views

Merge multiple files and format output into columns with line wrap

I'm trying to show multiple files to a user within less. These files have relatively long lines and contain the same text but in different languages (differences in line length to be expected). ...
Venem's user avatar
  • 11

1
2 3 4 5
13