Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

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
1 vote
0 answers
60 views

Wrap long lines using GNU sed

The following expression is reasonably effective at wrapping long lines of text (for the purpose of dumping to my 128 characters wide terminal window and reading): s~(.{104,124}) ~\1\n~g This ...
Lumi's user avatar
  • 864
1 vote
2 answers
62 views

Can I get the "detox" command to not change multiple hyphens to a single hyphen?

The detox command replaces multiple consecutive hyphens with single hyphens. For example, temp----tmp___tump.tmp becomes temp-tmp_tump.tmp. Can I modify its behaviour so that it keeps multiple ...
Roderick Stewart's user avatar
2 votes
1 answer
198 views

`printf` and `time` formatting issues in a `zsh` shell script

I have the following (excerpt from a) zsh shell script (the FOLDER environment variable is exported earlier in the code): # Create temporary directory export TMPDIR=$(mktemp -d) # Set TIMEFMT to ...
Markus Klyver's user avatar
1 vote
2 answers
83 views

How to pretty print one column of piped input?

bash 4.4.20 and jq-1.6 on RHEL8 I get this nice output from jq and column. Hard to read, though. pgbackrest info --output=json \ | jq -r '.[] | .backup[] | "\(.type) \(.label) \(.info.delta)...
RonJohn's user avatar
  • 1,473
0 votes
1 answer
55 views

Storing the iterations of the Receiver (or node) number and RSSI value into a file

I'm quite new to Linux. Recently, I've been able to create a bash script that allows me to obtain the RSSI of the receivers (or node) with a running iteration. How can I store these results in an text ...
Trinh Dat's user avatar
-4 votes
1 answer
90 views

file format help [closed]

input file Env Status (PRE) tomcat1 |-- Status : Running | Host : VVV | pid/s : 7427 |-- Status : Running | Host : VVV | pid/s : 489 |-- Status : Running |...
Rabindra Panigrahi's user avatar
0 votes
2 answers
97 views

In a text file, finding and deleting lines including (e.g.) "#', or a word? [duplicate]

I am using Ubuntu Linux and Mageia Linux... I wish to do the following: in a text file (sample.txt), find and delete every line comprising the symbol '#' (or '?') or a specific word (e.g. 'mobile') ...
Vinz M's user avatar
  • 11
1 vote
2 answers
363 views

Extracting table of contents from PDFs

I have a reasonably large personal library with books in various formats. I have tried to organize their metadata, including a text field containing the tables of contents. At the moment I am using ...
Luke's user avatar
  • 13
0 votes
3 answers
312 views

How to edit a string matching a pattern in a specific field on the condition another string is not present on the same line

I need to edit the string "NA" to "Na" only if it is in the 6th field of a file. I can currently achieve this with: awk '{gsub("NA","Na",$6)}1' $filename ...
CPC_92's user avatar
  • 3
0 votes
4 answers
232 views

Aligning space separated words in columns

There is a text file, file.txt. In there is: abc 01245 def-1 32154 ghi-3 55432 jkl 44121 mno-4 23147 pqr 897044 .... How to format this to an output like this: abc 01245 def-1 32154 ghi-3 55432 jkl ...
user447274's user avatar
0 votes
0 answers
61 views

is a cell boldface

I'm looking for a function to determine if a cell is formatted bold. I'm using LibreOffice Calc, and for ease of use, I have a range of items to buy and their prices. I want to have a simple method of ...
Michael Gehrke's user avatar
2 votes
1 answer
421 views

Cannot open an .mbox file with neomutt (although it works with mutt)

Cannot open an .mbox file with mutt I want to open a 10GB .mbox file that I downloaded from my gmail account. When I use the command neomutt -f 10GB_mboxfile.mbox neomutt takes 10-20 seconds to open ...
ecjb's user avatar
  • 495
0 votes
0 answers
80 views

Different format in .mbox and email saved locally with mutt: convert split .mbox file into the same format as mutt?

I am trying to move to mutt for mail client and am trying to have email localy. I have 2 sources of saved email: the first one was obtained from the .mbox file form google: I wrote a script which ...
ecjb's user avatar
  • 495
0 votes
1 answer
862 views

How do I change the date/time format in syslog-ng from `mmm [d]d hh:mm:ss` to `yyyy-mm-dd hh:mm:ss`?

I noticed that the default datetime format for logs in /var/log/messages is mmm [d]d hh:mm:ss, for example: Jan 4 03:46:50 1.2.3.4 ntpclient[6952]: Failed resolving address to hostname pool.ntp.org: ...
skeetastax's user avatar
0 votes
2 answers
81 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
275 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
85 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's user avatar
  • 159
2 votes
1 answer
75 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
201 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
-2 votes
1 answer
661 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 ...
Avocado's user avatar
  • 11
2 votes
0 answers
62 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
  • 274
1 vote
1 answer
84 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
788 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
124 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
171 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
  • 123
1 vote
2 answers
288 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
109 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
123 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
  • 145
1 vote
2 answers
77 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
60 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
249 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
177 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
  • 356k
3 votes
2 answers
2k 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
  • 19.4k
1 vote
1 answer
299 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) The list of such devices, as well as their PulseAudio ...
Marc.2377's user avatar
  • 1,202
1 vote
1 answer
307 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
2k 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
  • 521
3 votes
1 answer
2k 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
  • 1,043
-1 votes
1 answer
86 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
  • 129
3 votes
2 answers
390 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
221 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
2k 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
111 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,373
0 votes
3 answers
90 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
144 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
230 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
466 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,615
2 votes
1 answer
152 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 ...
camarman's user avatar
  • 153
0 votes
1 answer
251 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,615
1 vote
3 answers
321 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
127 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

1
2 3 4 5
13