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
0answers
12 views

Why Windows text files encoding crash after I open them in Linux system?

I use Debian and sometimes I need to mount Windows disks because I want to read some *.txt file from Windows. Sometimes it's okay, but sometimes after I edit or read file using Debian system and then ...
0
votes
0answers
25 views

Converting multiline to single line in a file looses double quotes

Here is my sample file cat test.txt "IND WEB", "Speed Web (Internal webserver)", "Web Bill", I tried the below two solutions to convert multiline to single line however ...
1
vote
1answer
47 views

groff: How can I correctly render paragraphs between embedded images?

I have the following groff source using the mom macros: .PRINTSTYLE TYPESET .CAPTION_AFTER_LABEL IMG .START .PDF_IMAGE img/uc1.pdf 657p 152p SCALE 70 CAPTION "Figure 1: Activity diagram for UC1&...
0
votes
1answer
28 views

Bash - Convert problematic space-separated table to semicolon-delimeted list

I have a program that outputs many lines of data in a space-separated table. I need to convert this output to a semicolon-separated list. This is an example record. Each field has a set number of ...
0
votes
0answers
16 views

Emacs Miner mode for subscript and subscript functionality from texinfo-mode

I am working on a minor mode that will use the superscipt and subscript functionality for texinfo-mode. Have been trying to see if the following works, which calls tex-font-lock-match-suscript. (...
1
vote
2answers
49 views

Right align last word in a line

…which does not exist in every line Example with | marking the maximum length of the line, say 79 characters excluding line-ending(s) and SPECIAL_WORD be the last word mentioned in the title: Some ...
2
votes
1answer
105 views

Escaping backlash and double quotes inside a sed expression (surrounded by double quotes)

$ echo 'output: " ' | sed "s/\"/\"/" output: " $ echo 'output: " ' | sed "s/\"/\\\"/" output: " $ echo 'output: " ' | sed "s/\&...
0
votes
0answers
7 views

Highlghting with Shift+Home and Shift+End do not work correctly on Manjaro XFCE on a Laptop Keypad

I found the solution to this problem to KDE (Highlghting with Shift+Home and Shift+End do not work correctly on Manjaro KDE on a Laptop Keypad) but that doesn't work for XFCE and I would really ...
2
votes
2answers
119 views

How to use column with tput colors?

Using tput colors seems to disturb the output of column. Why does this happen and more importantly is there a way around it? $ { echo "$(tput bold)foo$(tput sgr0)" "$(tput bold)bar$(tput sgr0)" ...
0
votes
3answers
77 views

Script for formatting code into columns

Often I have code that I want to align based on similar structure of lines, not just the left-side auto indent. Is there a script out there that can do something like this? Here is an example of ...
0
votes
1answer
36 views

How do I format the output of SQL query row-wise

Below query gets me the value in a variable called result result=`mysql --user=root --password=password1 deployment --host=localhost -Ns -e "SELECT DATE_FORMAT(LAST_DAY(url_timestamp), '%M %Y') ...
1
vote
1answer
30 views

Extract info in loops from specific column based on list of input

I have fileA and fileB. fileA is storing a list of names I wanted to extract from the second column of fileB. fileA: QW123 BH876 PR009 fileB: MJ194 PR009 100 PR009 IJ940 78 JG948 BH448 58 ...
-2
votes
1answer
73 views

How every group of N consecutive rows are folded into one, and separated by tab? [duplicate]

I am trying to solve one competitive question, where I'm stuck at below scenario can some one help me out to understand how the output can be achieved Explanation : Every group of three consecutive ...
1
vote
1answer
35 views

Match contents of first file with second to generate third file

Sample data of my first file first.txt is below: 10.0.0.1,Web Server,comments1,jboss is older version,myappcode1 10.0.0.3,Web Server,comments4,httpd is latest version,myappcode15 10.0.0.7,Web Server,...
4
votes
0answers
75 views

Text file with unknown header does not print propperly

I have a bunch of text-files that always come along with a backup file: 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 ...
-1
votes
1answer
61 views

grep and re-direct to csv

This is the campaign log that I am parsing. Based on call-id I do grep. Orginal Progress-log as follows: FilePlayer::run:: Finished audio file is /voip/VoiceCampaigSetup/wildfly-10.1.0.Final/...
1
vote
1answer
31 views

insert a blank line before and after a match on mac OS

my file contains the Strings: ∗Cast and characters * Bob Denver is Gilligan I want to insert the line * ATTENTION * to any line starting with * followed by one OR more spaces. it will be preceded by ...
0
votes
1answer
27 views

Remove Strings from two patterns/characters with sed

I want to remove the string inside two patterns/characters, so if I have a file containing "% Blah blah % i want to remove Blah blah as well as the pattern character in this case it will be % %. ...
0
votes
2answers
239 views

Replace a phone number using sed

my txt file contains the phone number (233)- 332-9888 and I want to replace that with ###-###-####. I'm doing s|[0-9]{3}-[0-9]{3}-[0-9]{4}|###-###-####|g (In extended mode), my issue is I don't know ...
-1
votes
4answers
71 views

File transformation

I have a two column file of the format;- A,val1 A,val2 A,val3 B,val1 B,val2 B,val3 What I need is to be able to transform the output of this so that the second column is horizontal for each unique ...
0
votes
4answers
56 views

Formatting numbers in a specific column of a file inplace [closed]

I'm trying to format the Amount col to 2 decimal format like 1000 to 1000.00 I have a sample file like below Bank|Branch|Comment|Amount|Extra1|Extra2 xyz|we||100|| xyz|we||100.1|| xyz|we|paid for inv# ...
0
votes
4answers
63 views

Need a script or command to append the previous line with the current line that starts with a lower case letter

The output I'm trying to format before opening the file in excel looks like this: 1. |1.99934| BD | 1| C 1 - H 2 | 60.12%| 0.7754* C 1 s| 24.99%|p 3.00| 74.95%|d 0.00| 0.05%| f 0.00| 0.01%| |...
1
vote
2answers
72 views

Detect odd characters in big text files

I need to check if my entire files contained only 4 characters; "A", "T", "G" and "C". I used to split the characters using sed and then grep -o and -v to ...
0
votes
5answers
239 views

Use sed to add string at specific column

I have a flat file containing columns of data representing fields from a table. I get the file from an outside source and want to insert the data into a table in my database. Unfortunately, the file I ...
-1
votes
2answers
157 views

Awk to convert TSV table into grid table [closed]

I want to convert a text table with tab as delimiter (i.e., basically a TSV file) to a grid table with lines on all borders (inside and outside) and text wrapping. The below is the input TrackId ...
1
vote
1answer
30 views

How to log CPU usage but only when it is high or touching certain treshold ? (+ formatting)

How can we log CPU usage but only when there is a process(s) with utilization above certain threshold (for example 30% or more) ? What i am trying to achieve (with shell script) are more or less like ...
5
votes
3answers
442 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 ...
0
votes
3answers
59 views

awk splitting problem with space

I failed to split after the first space with awk. $ grep ">" Supplemental_dataset_07_NbE_CDS.fasta | awk 'BEGIN { FS = "\t" } {print $1}' | head >NbD053290.1 Partial, ...
1
vote
3answers
104 views

awk's substr replacement

I downloaded a tab-separated file from here: ##gff-version 3 #!gff-spec-version 1.21 #!processor NCBI annotwriter #!genome-build Nsyl #!genome-build-accession NCBI_Assembly:GCF_000393655.1 #!...
32
votes
3answers
2k views

How can I convert a text file to columns like a newspaper?

I don't want to convert tabular data to nice columns like a standard awk recipe would produce. I want some text that's very long to be formatted into columns like a newspaper column. For example turn ...
0
votes
2answers
54 views

Showing both date and time in a single column

I am extracting time series data from NetCDF using Climate data operator. It has the option to extract Date as well as time separately. I have used cdo -outputtab,date,time,value -remapnn,lon=-85....
0
votes
2answers
68 views

set format with printf for $0

I compute the row average of the following data set however I have trouble setting the correct format for $0 so as to produce the file-output presented below. I currently have: awk '{T=0; for (i=1;i&...
0
votes
2answers
47 views

How to get certain last characets delimited by certain character?

I have a file , when i type this command i get this root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# cat hi | awk -F ' ' '{print $3}' | awk -F '://' '{print $2}' 127.0.0.1:80/bWAPP 127.0.0.1:80/...
0
votes
1answer
143 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
-1
votes
3answers
54 views

How to remove specific lines from a text file?

I have a text file F containing text in multiple lines and another text file L which contains list of numbers corresponding to lines in F I would like to remove all the lines listed in L from F In ...
0
votes
1answer
56 views

why does \n not go to a new line [duplicate]

I have several text files which should contain text in multiple lines. I can see that the \n is present where the text should go to a new line, but this is not working. I also noticed that there is no ...
-1
votes
3answers
72 views

How to insert comma after the certain character?

How can I insert a comma after a certain character but do not insert comma for the last record. I have data [ {"ID": 12345} {"ID": 67891} {"ID": 14785} ] so I am trying to insert a comma after ...
2
votes
2answers
45 views

Explanation of awk statement

I used this snippet of code to start a new column after every 20th row and each of the columns is separated by tabs. I took the code from this post and then tweaked it a bit: How to start a new column ...
4
votes
3answers
465 views

Number formatting and rounding issue with awk

I want to get the exact number when I try to find the average of a column of values. For example, this is the column of input values: 1426044 1425486 1439480 1423677 1383676 1360088 1390745 1435123 ...
0
votes
4answers
66 views

Concatinate a list of text into comma separated group of 6

I have a file test.txt which has huge entry a sample of which is below. Afghanistan Albania Algeria Andorra Angola Antigua and Barbuda Argentina Armenia Australia Austria Azerbaijan The Bahamas ...
0
votes
1answer
19 views

Is there a tool like 'watch' that can view cyclical output given a repeat marker

This seems to come up a few times. I'll be trying to spot differences in logs with repeating cycles. For example: start 1 2 3 end start 1 2 4 3 end Rather than scrolling through pages of terminal ...
0
votes
4answers
79 views

Renaming in sed to allow further match before substituting

I was trying to rename texts in fileA using sed. The second last column in fileA is where the full description of product names lies. I would like to substitute the product names with its ID. However, ...
0
votes
3answers
267 views

Inserting text with formatting at the start of a file with printf

I need to append something with particular formatting at the start of a text file. I have looked into How do I append text to the beginning and end of multiple text files in Bash, but not sure how to ...
5
votes
4answers
208 views

Delete line if next line starts with pattern

I'd like to delete a line if it does not start with "a" "c" "t" or "g", and the next line starts with '>'. In the following example, "`>seq3" is deleted. Input: >seq1 actgatgac >seq2 ctgacgtca ...
1
vote
2answers
39 views

How to remove unneccessary spaces from table output in shell while still keeping columns aligned?

Below command outputs a table of space delimited text, is there a tool to remove the unnecessary spacing here while still keeping the columns aligned? $ sudo ss -ltpn State Recv-Q Send-Q ...
0
votes
1answer
97 views

grabbing username and password hashes from /etc/security/passwd

I have a list of usernames which i need to sync their passwords over to a new server. How would I go about extracting the username and password hash from the /etc/security/passwd file into the below ...
0
votes
1answer
43 views

Sed change a tag and keep part of the contents

I have a large text file with multiple occurrences of a tag containing a URL: [tag]https://example.com/222389/link/11835457224168404[/tag] I need to reformat the tags as follows: [new-tag]...
2
votes
3answers
132 views

Use substitution to delete everything up to a point on a line

I want to use a global substitution in Vim to delete everything up to https. Before The website is https://website.com The website is https://website.com The website is https://website.com After ...
0
votes
2answers
346 views

awk column-wise division of all lines by another line

I'm trying to divide all lines in file1.txt by their respective (column-wise) value in the single line in file2.txt. cat file1.txt 1 2.5 3 7 7 7 1 3 5 cat file2....
2
votes
5answers
293 views

How to separate output records by ',' while avoiding the trailing comma in awk

Consider the following awk statement and its output: $ awk -F "/" '/\/tcp/ {print $1}' input_file 10\n 20\n The output I want instead is: 10,20 What I tried is: $ awk -F "/" 'BEGIN{ORS=","} /\/...

1
2 3 4 5
10