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
20 votes
4 answers
25k views

cat files in specific order based on number in filename

I have files named file.88_0.pdb, file.88_1.pdb, ..., file.88_100.pdb. I want to cat them so that file.88_1.pdb gets pasted after file.88_0.pdb, file.88_2.pdb after file.88_1.pdb, and so on. If I do ...
1 vote
2 answers
41 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 ...
-2 votes
2 answers
51 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|...
0 votes
2 answers
2k views

Change prompt with echo to show current directory

Problem: I was hoping this would be something simple to do. I currently have my script changing my directory among other things and I was hoping that I could make the script change the line using ...
-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 </...
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. ...
3 votes
1 answer
2k views

Edit HTML files from the command line

I'm looking for a way to edit HTML files from the command line similar to sed or awk, but using path expressions similar to jq or pup. In particular, newlines, white space and other formatting details ...
3 votes
1 answer
2k views

Why does Vim show these strange characters sometimes?

Why is Vim showing these strange characters? I'm running Arch, and locale -a gives this: C en_US.utf8 POSIX ➜$> I've also tried :set fileencoding=utf-8 But, that didn't help either.
3 votes
2 answers
306 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-...
1 vote
1 answer
53 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: ...
0 votes
1 answer
64 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/...
1 vote
6 answers
4k views

command that will take a file and separate each word so its on its own line

I have a file which has around 17523 words in it and I need to separate each word so it is on its own line (a word is defined to be a contiguous sequence of letters, so 1 letter words don't count) ...
0 votes
1 answer
2k views

busybox format date

I got a command which works perfectly on linux date -d @$(git log -1 --format=%at) '+%Y-%m-%d_%H-%M-%S' and now i'm trying to do same formatting with busybox, but i always fail
12 votes
3 answers
30k views

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 ...
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:...
3 votes
2 answers
100 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) ...
3 votes
1 answer
440 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 ("%...
-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-...
3 votes
3 answers
1k views

How to restrict awk number of fields?

Below is my test file. aa, bb, cc dd, ee ff, gg, hh Is it possible to make awk think we only have 2 fields for each record and the record separator is the first ,? So in my example, the $2 for each ...
3 votes
2 answers
135 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. ...
2 votes
1 answer
317 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 ...
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. ...
9 votes
6 answers
13k views

How can I print a variable with padded center alignment?

How can I print $myvar padded so that it is in the center of the terminal, and to either side are = to the edge of the screen?
4 votes
3 answers
550 views

Parsing csv file to filter rows basing on a matching set of characters from a column value

Consider the following csv file: A,3300 B,8440 B,8443 B,8444 C,304 C,404 M,5502 M,5511 The real csv file is really big (around 60,000 rows) but I only included a small version for ...
0 votes
3 answers
52 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 ...
17 votes
8 answers
4k views

How to process an x-column text file to get a y-column one?

I have a text file: a aa aaa b bb bbb c cc ccc d dd ddd e ee eee f ff fff g gg ggg h hh hhh i ii iii j jj jjj How can I process it and get a 2 ...
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 ...
1 vote
1 answer
386 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 ...
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&...
0 votes
0 answers
84 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 "...
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 ...
0 votes
1 answer
64 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 ...
0 votes
2 answers
498 views

read raw data from disk and convert

please help to find a way to convert the data as follows: I read from disk using dd utility dd if=/dev/sdb skip=8388608 count=560 iflag=skip_bytes,count_bytes |hexdump -C and I am getting ...
4 votes
2 answers
774 views

Create 'tree' output from list of files

I have a large list of directories and filenames in the format drwxr-sr-x hamiltont/hamiltont 0 2015-03-11 23:54 Archive/Directory One/Subdir/ -rw-r--r-- hamiltont/hamiltont 21799 2014-01-10 12:52 ...
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 ...
1 vote
2 answers
877 views

Pdftotext not making paragraph breaks

OSX, Homebrew's pdftotext works, but it does not honor the paragraph breaks. I have experimented with -pagebrk, -eol mac or -eol unix, but the problem of dividing paragraphs seems to be always there. ...
6 votes
3 answers
820 views

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 ...
1 vote
3 answers
181 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 } ...
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 ...
0 votes
1 answer
16 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 ...
4 votes
3 answers
697 views

Print table with empty columns for consecutive delimiters

I typically use column to convert input into a table, eg: $ echo 'a\tb\tc\nd\te\tf' | column -t -s $'\t' a b c d e f However it collapses empty columns eg: $ echo 'a\tb\tc\nd\t\tf' | column -t -...
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 ...
2 votes
2 answers
254 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 ...
3 votes
5 answers
2k views

Convert separator character while escaping separator in fields

I have a text file with fields delimited by |. I want to convert it to , like a typical CSV. I have tried to use this: sed 's/|/,/g' test.txt > test.csv but some of the fields already have ...
3 votes
6 answers
792 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,...
1 vote
2 answers
540 views

Two consecutive OPs after pipe or two jq OPs in one run?

I have to extract data from a slightly mis-formatted JSON string, hence I first pass it through sed & awk. What I have is a command like: `sed 's/},/},\n/g' test.json |awk '/"characater"/ { gsub("...
18 votes
4 answers
36k views

How can I pretty format a JSON file, with all the correct indents and everything?

I have a JSON file on CentOS where all text is on the same line. How can I pretty format it with all the correct indents and everything?
-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 ...
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....
7 votes
4 answers
12k views

Print two files in two columns side-by-side

I want to output two text files in two columns — one on the left side and other one on the right. paste doesn't solve the problem, because it only insert a character as delimiter, so if the first file ...

1
2 3 4 5
12