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 [tag:printf]. For date format strings, [tag:date]. See also [tag:text-processing].

Filter by
Sorted by
Tagged with
-1
votes
3answers
42 views

How to turn a single column into three?

How may I distribute a single column of data over three columns? Input: A B C A B C . . . I want the following result: A B C A B C A B C . . .
0
votes
1answer
72 views

How can I edit txt to xls in Unix?

I want to convert my txt file to xls/csv. The first row should print datetime and second row should print the remaining all data (from tid to table in below example) When m using the below command ...
0
votes
6answers
76 views

multiple column alignment

I've my raw data as - id=ABC name=Banana DB Connection type=FruitMarket XYZ_1 ABC.xml XYZ_2 ABC.xml XYZ_3 ABC.xml "Fruits/Mango/#Common" "Fruits/Mango/#Bizzare" "Fruits/...
2
votes
1answer
40 views

How to enable underlines and other formattings on a color tty?

I'm on Arch Linux (a 32 bits alternative version), and recently I've discovered that the blue lines I used to see in Vim with :set cursorline were supposed to be underlined, and not blue. That got me ...
9
votes
5answers
1k views

Bash - draw a vertical line behind lines with variable length

I have a textfile that has the following format and I want to add a vertical line after those lines, followed by increasing numbers: c4-1 d e c c d e c e-2 f g2 e4 f g2 g8-4\( a-5 g f\) e4 c g'8\( a ...
1
vote
0answers
22 views

Is there a way to make `man` reflow text when the terminal window is resized? [duplicate]

man apparently uses less -s as the default pager, which does reflow text when the terminal window is resized, but this does not happen in man. Is there any way of making man reflow text, so that it ...
-1
votes
0answers
27 views

AWK format help [duplicate]

I have a large file formatted like this rs62635285 1 12807 CC rs574746232 1 13011 TT rs540538026 1 13110 GG That I want to look like this "rs62635285","1","12807","CC" "rs574746232","1"...
0
votes
2answers
54 views

How to split a text file so that each paragraph is its own file?

I have a long list of urls, and I'm trying to make a shell script to split each paragraph, separated by newline, into its own file. The files would need to be numbered 001 002 003 ... and so on. ...
0
votes
2answers
48 views

How to align two columns that have empty spaces?

I am trying to align two columns one of which sometimes have empty spaces I am using that code #For the first column awk '{print $9}' PMZ_genes.gff3.txt | grep -oP ";\KName=[^;]+" #For the second ...
1
vote
5answers
174 views

how to remove the row spaces using cut command

from this: 1 2 3 4 5 6 The result should be like this: 1 2 3 4 5 6
1
vote
1answer
30 views

How to JSON-escape input?

I am trying to come up with a tool what for sending data up to a github gist via the API. The problem is the github api takes the gist content as a single line with all escape sequences written out ...
-2
votes
4answers
60 views

Extracting specific value from a file

I have a sample file like this. Zone A Total Population 500 unit Total Area 150 sq. unit Zone B Total Population 600 unit Total Area 200 sq. unit Zone C Total Population 400 unit Total Area 100 sq. ...
2
votes
2answers
48 views

How to calculate n values in a column and the overall average?

I would really appreciate some help with this as I am relativity new to Linux. I'm using grep but I also want an average of all of my extracted values (irrespective of which column they are in) and ...
1
vote
2answers
38 views

Replace single field numbers with double field numbers (1->01)

beginning with male 9 male 11 male 9 male 1 female 4 female 13 male 14 sort -u -k1,1 -k2,2n returns female 13 female 4 male 1 male 11 male 14 male 9 male 9 how can I make these numbers show as ...
-2
votes
2answers
58 views

How can I manipulate contents of a text file into a new output file

I have an input text file that looks like this: table columns are: number of vertices total surface area (mm^2) total gray matter volume (mm^3) average cortical thickness +- standard deviation (mm) ...
-1
votes
1answer
57 views

Append text to start of last line

How do I append something = to the start of the last line of a text file in Linux AAA BBB CCC DDD to AAA BBB CCC something = DDD
2
votes
1answer
29 views

How to neatly paste lists as columns? [duplicate]

I have two lists of words: $ head -n 15 words.txt > list1 $ tail -n 15 words.txt > list2 I paste them together into columns: $ paste list1 list2 The result is this, with tabs between the ...
0
votes
1answer
47 views

How to print the result of the awk command with the custom header

am trying to print the all the running services in my machine. For that i use the command a=$(sudo systemctl list-units --type service --all | grep running | awk -v OFS='\t' '{ print $1, $2, $4 }') ...
1
vote
1answer
65 views

Is there a good automated way to make a generic block of text square?

I often take long equations from Mathematica that are too long to ever be readable and bring them into C. Mathematica puts in a lot of newlines that I want to get rid of such that it fits nicely into ...
2
votes
2answers
105 views

Format columns in output with awk

I have the follow data set name a.txt with 9003 rows: 571 43544000424023503222 572 43504442020202303202 573 40340440323043033204 574 40303445340343505242 ... ... 16078 50200000023322000202 ...
0
votes
3answers
57 views

change format of uniq -c command

I want to get the unique words and its count from a file. When I run the bellow command, sort words.txt | uniq -c 2 america 4 and 1 england 1 file 1 for 1 place But I want the ...
0
votes
2answers
27 views

Extracting columns from Fasta file in Linux

I have a fasta file which looks like this >ENST00000632684.1 cdna chromosome:GRCh38:7:142786213:142786224:1 gene:ENSG00000282431.1 gene_biotype:TR_D_gene transcript_biotype:TR_D_gene gene_symbol:...
1
vote
2answers
27 views

Add number from x to y to every row

I have a file which contains 1 word per line. I need to add every number from 75 to 99 to every row (aka word). Example input file: foo bar Example output to a new file foo75 foo76 foo77 ... foo99 ...
10
votes
4answers
287 views

Modify width of first column in file with a variable number of fields, using awk

I understand how to use awk's printf function, but I don't want to specify every field. For example, assume this is my file: c1|c2|c3|c4|c5 c6|c7|c8|c9|c10 c11|c12|c13|c14|c15 I want to format it ...
1
vote
3answers
63 views

Paste texts on alternate lines

Let's say there are two files, "main" and "rename". The file "rename" has a few lines with names for appending on the alternate rows of file "main". (according to the position in the "rename") I has ...
3
votes
2answers
104 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 ...
-2
votes
2answers
66 views

Help with indexing a list of values

I need to track a huge log and more exactly a column. In this column I have some integer values in a rage between 103 and 17431. Example of original file 402 402 402 667 942 342 990 402 For every ...
0
votes
1answer
37 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. ...
-3
votes
1answer
51 views

String generator to file [closed]

How to generate strings by the following pattern Only ASCII letters and numbers. All letters are capital and string must be 14 chars long. All strings I need to write down to a file (Every string on ...
0
votes
2answers
29 views

Delete everything that isn't between brackets

I want to delete everything that isn't inside brackets, including the brackets, only in lines that start with ">". Is there a sed alternative? Also, would like to sort lines in alphabetical order by ...
1
vote
5answers
69 views

How to restructure a date variable in bash

I have a bash script that takes user-inputed dates in this format: dd.mm.yyyy and saves it as a variable $date Now I need to modify this variable to be in this format: yyyymmdd for further use. So ...
1
vote
1answer
40 views

Concatenate specific lines and output the results in a new file

I have multiple text files such as: file1: >ID_000_FLNNKGHD_01376 -ATGAATACAGAGGAAAAAACACCGCTTGCATACAAT >ID_000_MGCDKLCO_02388 ATGAAGGTGGAAAAAACACCGCTTGCATTT >ID_000_OMAMOGKP_02746 --...
0
votes
1answer
97 views

Clean formatting of output within bash scripts

I ran across a problem formatting the output during runtime while preserving the format of the code in some scripts. The below works for me, just wanna check that it's reasonable? It seems to dirty up ...
0
votes
1answer
21 views

Impose response formatting as a key value string

Let's suppose I invoke the following command: pwd && ls -l and I would like to receive response in a desired format for example: [CurrentDirectory=[here_result_of_pwd]] [...
1
vote
1answer
43 views

How to grep multiple lines?

Grep understands this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "clipper-coin" But not this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "{*clipper-coin*}" The output I ...
4
votes
4answers
161 views

How to format a file in csv format after the first comma in a line?

I have a file in the following format: Original format ARX_10/model2,...
0
votes
0answers
61 views

Is it possible to display curly error underlines in terminal vim?

I want to underline errors in vim like in this example gif from the ALE github page. Though as of yet I have only been able to get gVim to display curly underlines. Is it possible to get curly ...
1
vote
4answers
3k 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 "...
7
votes
3answers
1k views

Quickest way to move a line in a text file before another line in a text file?

I have the line number 55 in a text file which I want to move just before line number 23 in the same text file. I know that you can move lines up by a certain number of lines 1, 2 but is it possible ...
2
votes
2answers
198 views

Command for converting rows to CSV file

I have a file of the format, with a leading space before each line: "Western Overseas", "Western Overseas", "^", "--", "^", "--", "--", null, 24995, 9977, "CR", "Western Refrigeration ...
1
vote
2answers
181 views

Replace a string pattern by a sequence using sed

I want to replace a string in a text file with a sequence of numbers such as 1 2 3 4 5 6 7 preferably using sed. Here is what I have tried (without the search string) and seems to work: for i in {1.....
0
votes
2answers
51 views

How to always print an output with certain number of digits using AWK

I have the following command: find . -mtime -5 -type f -exec ls -ltr {} \; | awk '{print "cp -p "$9" "$7}' the output is like: cp -p ./18587_96xxdata.txt 10 cp -p ./16947_96xxdata.txt 8 cp -p ./...
1
vote
2answers
37 views

group list by last string of each line

I'm having a list of strings (sorted IP address ranges) like this: 10.100.0.0-10.100.255.255 External: 2.2.2.2 10.120.0.0-10.255.255.255 External: 2.2.2.2 10.0.0.0-10.255.255.255 External: 3.3.3.3 ...
1
vote
1answer
27 views

how to print hyphen in double quotes along with other strings

cat inv_summary_1.txt | while read -r aLine do F1=`echo "$aLine" | cut -d "," -f1` F2=`echo "$aLine" | cut -d "," -f2` echo " 0 RUN_ID STR [0] \"${F2}\" " done 191245204696,REG-...
1
vote
1answer
93 views

Convert XLS file to CSV file in perl without using spreadsheet [closed]

I have a file in .XLS format and I want to load that file on Informatica, for which I need to convert that file to .CSV, i.e. XLS to CSV.
0
votes
1answer
28 views

Output of sar is difficult to read

I want to display statistics for devices. When I use sar -d I only see tens of devices with names that are hard to interpret: Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz ...
1
vote
4answers
51 views

How do I extract with sed numeric characters between two characters?

I have a random text, followed by a colon (:) and a space, then a numeric result, then another space and other arbitrary text; for example: text: 30 (5 new) I need to extract only the number 30; for ...
0
votes
1answer
55 views

Convert specific number in file in awk

I have a big problem. I have a file like: 18 13 8 5 3 1.715 2.845 1.046 -5.607 -0.000 0.000 38 34 29 24 3 1.715 2.845 1.046 -5.607 -0.000 ...
1
vote
2answers
74 views

How to merge lines (of a multi-line code routine)

I have a file; contents are as follows: cat -n /tmp/my_file 1 verify(abc) { 2 foo : bar; 3 sub1(aa) { 4 line1; 5 } 6 sub2 (bb) { 7 line1; 8 // this line is a comment ...
2
votes
4answers
173 views

Replacing multiple matched strings using columns in guide file

I have 2 files (FileA & FileB), FileA: s12 >g01 s16 >g02 s48 >g03 s52 >g04 s80 >g05 s81 >g06 s87 >g07 s91 >g08 s92 >g09 s93 >g10 s94 >g11 s96 >g12 s97 >g13 ...