2022 Developer Survey is open! Take survey.

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
5 views

Libre-office: Texmaths extension disappeared and can not be reinstalled

So I've been using Texmaths, an extension for Libre-office for 2 months. Suddenly, yesterday Libre-office closed (happens sometimes), but then when I reopened it the button for the extension had ...
user avatar
1 vote
4 answers
54 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:/\...
user avatar
  • 183
2 votes
2 answers
56 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 ...
user avatar
  • 1,631
5 votes
5 answers
369 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 ...
user avatar
0 votes
0 answers
12 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 ...
user avatar
0 votes
1 answer
55 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 ...
user avatar
  • 297
0 votes
2 answers
95 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> ------ ...
user avatar
  • 297
0 votes
1 answer
40 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' ...
user avatar
  • 297
0 votes
2 answers
29 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 ...
user avatar
1 vote
1 answer
55 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 ...
user avatar
0 votes
1 answer
29 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 ...
user avatar
0 votes
3 answers
69 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 ...
user avatar
0 votes
7 answers
113 views

AWK: Concatenate field from different records

Given file: 2018-03-22 foo/bar/baz 2020-09-30 Lorem/ipsum/dolor 2021-10-01 yadda/yadda/yadda 2022-03-14 blah/blah/blah (actual files contain thousands of such lines) How to obtain the string 2018-03-...
user avatar
1 vote
5 answers
41 views

How can I add a single empty row after a certain number of rows from a txt

This is the text file Drives.txt: Slot Number : 0 Drive's position : DiskGroup 0 Media Error Count : 0 Other Error Count : 0 ...
user avatar
0 votes
1 answer
42 views

Display `grep -lr` results as a tree

I'm searching a large number of text files which are organized in various subdirectories. I can run a command such as grep -lr foobar ./, and I get results like the following: ./dirA/dirA.A/abc.txt ./...
user avatar
  • 201
1 vote
1 answer
13 views

Reorder iostat output with time next to the device column

I am trying to reformat the iostat data. Current output: TimeA Column1 Column2 Column3 disk1 10GB small disk2 20GB medium disk3 30GB large TimeB Column1 Column2 Column3 disk1 ...
user avatar
  • 11
0 votes
1 answer
16 views

Xsetroot output truncation?

I've been working on a config for dwm 6.3 with a bunch of patches (on GuixSD, if it matters). Most of them haven't been updated to work on 6.3, so it's been a lot of effort to get everything sorted ...
user avatar
  • 101
-1 votes
2 answers
38 views

Extract Metadata from DDL

I have a created a file with list of tables present in a particular schema. I need to extract the column details for each table and need to write it to another file describe test_table +-----------+---...
user avatar
0 votes
0 answers
29 views

How to convert a multiple choice text file into a json file with indents

How can I convert a text file into a JSON output like below? Text file: Question:'Which of the following commands can be used to perform a full text search on all available packages on a Debian system?...
user avatar
0 votes
1 answer
77 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 ...
user avatar
  • 1
1 vote
6 answers
257 views

count duplicate entries within each column

My file contains a hundred of columns. I need to: first counting duplicates entries within each column then display output columns order by the number of rows (max to min). Input file: a b c ...
user avatar
  • 35
-1 votes
5 answers
121 views

How to break comma-separated fields into separate lines

Input file: A B C D 1 2,3,4,5 6,7 8,9,10,11 Output file: A B C D 1 2 6 8 3 7 9 4 10 5 11
user avatar
  • 35
0 votes
5 answers
75 views

Move the line matching to the Immediate next line to the end of matching line

I have input like this ,i need move the line after *_job to the end of the *_job line, if it is job_type and print the entire file. IF the next line is not job_type just print them. i able to print ...
user avatar
  • 183
1 vote
3 answers
54 views

Restarting poem line numbering any 4 lines after a blank space

This is related to very interesting answer given here: Any text utility or hack to numbering poems lines omitting certain numbers? awk 'FNR % 4 == 0 { printf "%6i %s\n", FNR, $0 ; next }; {...
user avatar
  • 297
1 vote
1 answer
76 views

Appending spaces to the rest of fixed length record in UNIX Script

I have the data for about 40 characters in the record of 250 length(FIXED). But I want to append the remaining 250-40=210 characters with SPACES. How do we do in UNIX Script?
user avatar
0 votes
3 answers
49 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 ...
user avatar
  • 21
7 votes
6 answers
816 views

Uppercasing first letter of a line after period in previous line

I have many little poems to edit like this: Io avevo due sorelle, una bionda e l’altra mora, tutte e due leggiadre e belle e gentil come l’aurora. ma la bionda mi è sparita, se ne è andata all’altra ...
user avatar
  • 297
0 votes
1 answer
146 views

Match multiple patterns in text file, copy and modify the matched line

I want to match multiple patterns in text files on the same line, copy and modify the matched line. I want to duplicate every line that contains either the string "businessServices" or "...
user avatar
1 vote
1 answer
482 views

How to format hexdump as xxd, possible for xxd -revert?

I wish to dump the raw content of a SD card into a file for inspection. Most parts of it are zeroes. Learnt from this SuperUser answer I could use pv to show the progress of od and hexdump. Both ETA ...
user avatar
  • 233
3 votes
3 answers
243 views

Numbering poems stanzas using roman numerals

I would be able to numbering, sequentially, any stanza of a certain poem using roman numerals like this: Injurious love, why still to mar accord Between desires has been thy ...
user avatar
  • 297
-3 votes
2 answers
109 views

awk or sed to format variable durations

Tried a lot of awk and sed commands, but cant get the file to format properly. The primary issue is with handling of extra comma in the middle of a column that exits sometimes and doesnt exist other ...
user avatar
  • 95
1 vote
1 answer
126 views

How to display the contents of a text file in columns [duplicate]

I have a file as follows Id 123 Name john Lastname udosen Tel 123456 Id 124 Name james Lastname david Tel 19865 How i can to print file as follows Id Name Lastname Tel 123 john ...
user avatar
-5 votes
2 answers
126 views

Change values of last column [closed]

I have input like this i tried to replace the last Grade columns with 9 as AB, 12 as RE, 23 as A1, 34 as FA is there any way to change the grade columns with said values. Input: ST NAME MATHS PHY ...
user avatar
  • 23
1 vote
2 answers
85 views

shortcut command for printf with a specific format string

I want to use a shortcut command for printf with a specific format string, and came up with the following. local PF="printf %s\n" $PF "Some Text" It does the job, but wonder if ...
user avatar
0 votes
1 answer
23 views

column --table-noextreme

How does the --table-noextreme option of column work? -E, --table-noextreme columns Specify columns where is possible to ignore unusually long (longer than average) cells when ...
user avatar
  • 4,841
1 vote
2 answers
84 views

Split one line into multiple lines while keeping the first column

Is there any way to re-format a text file from 'n n / [ ] / m / N 'ns @ s / @ z / @ / j @ z / j @ s 'r r 's s / z / [ ] ... to 'n n 'n [ ] '...
user avatar
1 vote
3 answers
330 views

Center text with printf

printf "%*s\n" $(((${#fname}+$COLUMNS)/2)) "$fname" I get this error: line 9: (7+)/2: syntax error: operand expected (error token is ")/2") This works in the terminal ...
user avatar
2 votes
4 answers
249 views

Reformatting text using sed or awk

I have a input like where first row is the header, is it possible to reformat the text as the output below? awk '{if ($2=="b" || $3 == "c" || $4 == "d" || $5 == "e&...
user avatar
  • 23
0 votes
3 answers
87 views

Merge two strings in a line where | delimiter

I want to merge two strings in a line with | as the delimiter. We can combine by using awk '{$1,$2,$3$4$5}', is there any other way to merge the string using | as the delimiter? Input: XXXXXXXX 0 ...
user avatar
  • 183
0 votes
0 answers
32 views

awk output not in columns when moved to log [duplicate]

I have an awk command piped to the output of another command | awk {'print $2,$3'}. When I run this command the output displays the data in columns, of the columns as I would expect column2 column3 a ...
user avatar
  • 13
0 votes
2 answers
78 views

Align numeric values to the right (recfmt output)

I'm making a Unix database in a plain text with GNU Recutils. With the following script I get a books list of a selected category: recsel -t book -e "Category='$1'" "$RECFILE" | ...
user avatar
  • 180
-1 votes
1 answer
76 views

Linux shell script to convert rows into column data [duplicate]

I want to convert data from below input file, converting rows tp columns: Input: Avamar Hostname server1.corpnet2.com Avamar Server Version 19.1.0-38 Node Type ...
user avatar
0 votes
1 answer
76 views

A command for a perfect justify / formatting on Linux

I have a text like this Transport Layer Security (TLS) and its predecessor Secure Sockets Layer (SSL) are cryptographic presentation protocols used in the telecommunications field I want a "...
user avatar
  • 10.9k
0 votes
1 answer
52 views

extract data from text formatted in columns

I have multiple lines I would like to extract from text formatted in columns. How do I get the entire column? Column1 Column2 Column3 textA textB textC textAA textBB textCC I am familiar with ...
user avatar
  • 13
5 votes
2 answers
416 views

What text editor supports positioning the cursor anywhere, even beyond the end of line?

I want an editor that can put the cursor anywhere in the text document, as if it were filled with spaces everywhere. This way I can place the cursor anywhere and type or paste right away, without the ...
user avatar
  • 739
2 votes
2 answers
100 views

Shell script print single line output based on starting and ending parameter present in single line or multiline

My File is: "abc"..,,xyz 123 "New york".."END" <- # Print this entire line as starts with " and ends with "END" "mnh".....blahblah ...
user avatar
  • 23
1 vote
2 answers
120 views

Best way to pad stdin to desired length with NULL

I have the following requirement. I have an input stream that I need to truncate to a certain fixed length of bytes. I do not know the length of the input stream beforehand. If the stream is less in ...
user avatar
7 votes
2 answers
7k 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 ...
user avatar
0 votes
1 answer
245 views

Is there a command line application that can prettify text containing HTML + CSS + JS?

I work on Geany because it is lightweight and simple. But one future I really miss from using sophisticated and heavy code editors is prettifying the code with a keystroke. But Geany allows external ...
user avatar
  • 23
2 votes
3 answers
215 views

Split fixed width file into lines

Have a fixed-length file where there is no newline separator between the lines, but every line is exactly 15 characters. echo "John Doe Jane Doe Johny Doe " > /tmp/...
user avatar

1
2 3 4 5
12