As of May 31, 2023, we have updated our Code of Conduct.

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
2 answers
43 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
52 views

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|...
Rocky's user avatar
  • 3
-1 votes
3 answers
83 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
27 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
  • 316k
3 votes
2 answers
310 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.1k
1 vote
1 answer
55 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,052
0 votes
1 answer
67 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
3 votes
3 answers
529 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
  • 429
3 votes
1 answer
442 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
  • 925
-1 votes
1 answer
30 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
136 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
102 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
323 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
74 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. ...
Veak's user avatar
  • 141
0 votes
3 answers
53 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
111 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
0 answers
85 views

How to label gnuplot data points with two columns' data points (e.g. 11-15-21, 453)

I'm generating a bar chart to svg and I've added nicely formatted data labels to a bar chart with the plot command: plot 'trend.csv' using 1:3:(sprintf("%+'0.0f",$3)) with labels font "...
gessel's user avatar
  • 311
0 votes
2 answers
152 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
  • 358
0 votes
2 answers
100 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,085
2 votes
1 answer
83 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
65 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,085
1 vote
3 answers
182 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
39 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
17 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
53 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
256 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
133 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
335 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
59 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
122 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
  • 417
3 votes
6 answers
795 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,889
0 votes
2 answers
260 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
69 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
41 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
2 votes
2 answers
182 views

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 ...
Dingo's user avatar
  • 329
1 vote
3 answers
177 views

Creating a csv file from formatted ascii input

I am using Linux. I have a file of the following format ; Header info ;--+-----+--+----+-+---------------- ;Co TASK# ID PROP X Remarks ;de (full desc.) ;--+-----+--+----+-+---------------- AAA P00_1 ...
mcr's user avatar
  • 11
0 votes
1 answer
613 views

Change column width size in command output

I have the output from a command in which some text is hidden due to the column width size; are there any commands that can help display all of the output in that column? Currently, I use the grep ...
Sajesh Achari's user avatar
3 votes
1 answer
155 views

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 ...
400 the Cat's user avatar
1 vote
4 answers
309 views

Split the line into next line after a matching pattern

In the input file shown below, I am trying to find the string job_type and move the it to the next line if it matches job_type. I tried this, but it is not working: sed "s/[A-Z][a-z]*job_type:/\...
Renga's user avatar
  • 393
2 votes
2 answers
427 views

awk replace column value with increment values if length equals

I have non-standard data, which I'd like to standardise file: d101 11001 e101 9665 f101 9663 d102 11002 e102 11003 f102 11004 g102 11005 desired output: d101 11001 e101 12001 f101 12002 d102 11002 ...
Sollosa's user avatar
  • 1,885
5 votes
5 answers
1k views

If column has multiple values, copy line with each value separately

I have a file with the following format, each column separated by tabs: C1 C2 C3 a b,c d e f,g,h i j k l ... Now I need to have the number of lines according to the number of values ...
schrodingerscatcuriosity's user avatar
1 vote
1 answer
389 views

How to print text files using CUPS configurably

When I try to print a text file using CUPS, it comes out with a very small font and negligible margins: head -n 450 /usr/share/dict/words | tr '\n' " " > t /usr/lib/cups/filter/texttopdf ...
Metamorphic's user avatar
  • 1,101
1 vote
1 answer
2k views

How can sed replacement string be a command's output?

Below sed command helps add text Hello to the end of each line of the input <complex_query> | sed "s,$,Hello," Output: myvar1: Hello myvar2: Hello I now wish to have the output of ...
Ashar's user avatar
  • 417
1 vote
2 answers
3k views

split string using a substring as delimiter and get the later part

Here is my string LIBRARY_TRGT_CANV,CANV_MATCH<anything> I wish to get all the text after last occurance of our delimiter which is _TRGT_: Desired output: CANV,CANV_MATCH<anything> ------ ...
Ashar's user avatar
  • 417
0 votes
1 answer
96 views

Need help Formatting a file having key: value [duplicate]

I have a file having the below values: cat data.txt server1: 'calv' server2: 'anot' log: '/u/log/1' server3: 'calv' server4: 'anot' server5: 'secd' server6: 'calv' LIB_TRGT_calv,anot: '/tmp/hello.txt' ...
Ashar's user avatar
  • 417
0 votes
2 answers
45 views

How to keep my third column straight if my second one changes

I have this output from a command. CPU_SrcID#0_MC#0_Chan#0_DIMM#0 0 0 A1 CPU_SrcID#0_MC#0_Chan#1_DIMM#0 0 0 A2 CPU_SrcID#0_MC#0_Chan#2_DIMM#0 0 0 A3 CPU_SrcID#0_MC#1_Chan#0_DIMM#0 ...
Josue Baquerizo's user avatar
1 vote
1 answer
81 views

How does the default -s option of the "column" command work? How can I mimic the default -s option by manually passing it some value?

The manpage of the column command describes the -s option like this: -s, --separator separators Specify the possible input item delimiters (default is whitespace). It says by default, -s is ...
Fajela Tajkiya's user avatar
0 votes
1 answer
92 views

Understanding of the expand command

I can't fully understand how the -t parameter of the expand command work. Below is an excerpt from its manpage. NAME expand - convert tabs to spaces ... -t, --tabs=N have tabs N ...
Fajela Tajkiya's user avatar
0 votes
3 answers
77 views

Pull certain lines of text out of a large group of files

I am trying to yank all of the individual Unix commands out of a large group of text files. Here is what I have so far: In this example I am pulling out all instances of the tx command.  The big group ...
Mountains792's user avatar

1
2 3 4 5
12