Skip to main content

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
13 votes
3 answers
17k views

How to use Awk to format numbers with a thousands separator

Can anyone tell me how to use the awk command for this statement "the number will contain commas after every three digits. For example, 100000000 will become 100,000,000." I know how to use sed ...
0 votes
4 answers
2k views

Split a string into separate words

I can print a string using echo in bash shell-like echo "This is a sample string". Is there some command I can use as a pipe or some arguments to echo after the string that could result in ...
0 votes
0 answers
22 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 ...
2 votes
1 answer
127 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 ...
0 votes
0 answers
30 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 ...
24 votes
3 answers
61k 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 ...
0 votes
1 answer
57 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: ...
4 votes
1 answer
352 views

Text file with unknown header does not print properly

I have a bunch of text files that always come with a backup copy: file.TXT file.BAK the *.TXT file contains a header like this: .V3 PL=62 MB=1 MT=1 DR=TMTYM FL=0 FT=0 # ...
0 votes
0 answers
70 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 '...
0 votes
2 answers
42 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 ...
4 votes
3 answers
677 views

Parsing csv file to filter rows based 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 actual csv file is big (around 60,000 rows). I have only included a small version to describe ...
1 vote
2 answers
80 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 ...
1 vote
1 answer
28 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.
2 votes
1 answer
47 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 ...
9 votes
3 answers
4k views

Issue with column command and color escape codes

I'm colorizing the header of a table formatted with column -ts $'\t' Works well without color codes, but when I add color codes to the first line column doesn't properly align the output. Without ...
18 votes
4 answers
40k 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?
3 votes
3 answers
2k views

Why the output of "column" is misaligned with a ANSI colored input?

I'm working on a commandline that retrieve some data (curl), extract the relevant fields (awk) and format it (column). It work nice, although it's very ugly (but all my script begin from a "too long ...
-1 votes
3 answers
818 views

Print 1st column of 1st row and 2nd column of last row, where last column has same value [closed]

The desire here is to look at any rows with a common, sorted third row, and to give output based on this group of rows. (Note there are other properties of the table besides the common third row, but ...
1 vote
4 answers
677 views

Process `find` output parse out certain fields

I have find output as follows: /var/data/run/stores/user.rstd/info.settings:4: Password = "xxxxxxx"; In this example, "user" and the value of "Password" ("xxxxxxx&...
0 votes
0 answers
92 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 ...
-2 votes
1 answer
223 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 ...
2 votes
0 answers
40 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 ...
1 vote
1 answer
63 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': ...
3 votes
5 answers
748 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 ...
0 votes
2 answers
3k 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 the same formatting with busybox (v1.31.1), but it always fails with ...
3 votes
2 answers
2k views

Make JSON from SQL query output

I have this database query: select hostname,size from tableinfo The output is like this: hostname size ------------------------- ----------- host1 28 ...
1 vote
1 answer
85 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 ...
1 vote
5 answers
138 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'...
17 votes
9 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 ...
1 vote
2 answers
195 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 ...
0 votes
0 answers
64 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 ...
16 votes
5 answers
55k views

How to use the 'date' command to display week number of the year?

I want the UNIX date to output: So this is week 35 of 2016. Here, of course, 35 and 2016 are outputs of the date command. I have tried the following: date +%U This printed out the current week ...
3 votes
1 answer
3k 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 ...
12 votes
5 answers
56k views

AWK - print range of columns

if I have a csv file in the following format: column1,column2,column3,column4,column5,column6,column7,column8 and I want awk to only print columns 2 till 7 I would use: awk -F',' '{print $2 "," $3 "...
49 votes
4 answers
70k views

Bash shell script output alignment

My script: date echo -e "${YELLOW}Network check${NC}\n\n" while read hostname do ping -c 1 "$hostname" > /dev/null 2>&1 && echo -e "Network $hostname : ${GREEN}Online${NC}" || ...
0 votes
0 answers
71 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 ...
7 votes
6 answers
4k views

How to make `column -t` ignore lines with specific characteristics?

I just thought how neat it would be to pipe my /etc/fstab through column -te to get a nicely formatted table. But column of course has no way to discern comment lines and mountpoint definitions, so ...
1 vote
1 answer
221 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/...
3 votes
2 answers
87 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; ...
3 votes
4 answers
4k views

Splitting CSVs with multiline cells

I'm working with some CSV files generated by YouTube (so I cannot change the source structure). In the CSV file, some records span multiple lines. A hypothetical example with many other columns ...
21 votes
4 answers
28k 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
55 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
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|...
0 votes
2 answers
3k 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
136 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
63 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

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
1k 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
243 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: ...
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) ...

1
2 3 4 5
13