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
1
vote
1answer
22 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
22 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
68 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
68 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
51 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
58 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
62 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
72 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
106 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
23 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
379 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
58 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
98 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
36 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
46 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
52 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
46 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
51 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
57 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
39 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
241 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
64 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
15 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
77 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
72 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
152 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
30 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
40 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
34 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
104 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
164 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
122 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
vote
2answers
50 views

I want to only remove grouped commas from this csv to change the number of variables to two

I have a csv where the first few rows look like this c("4288", "57534"),MIB1 c("2272", "2385"),FHIT c("5550", "10531", "56239"),PREP c("25809", "23669"),TTLL1 I want to manipulate the number of ...
0
votes
2answers
65 views

creating line breaks after commas - before desired line width

In a file like: ruler 1 2 3 4 5 6 7 8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 \usage{ function( ...
-3
votes
2answers
48 views

How to format columns using awk? [closed]

The file rectData.ssv contains: rectangle1;1;2 rectangle2;1;10 rect4;10;10 How could the following command be changed to align the columns: $ awk -F ";" '{ print "area of", $1,":", $2 * $3}' ...
0
votes
2answers
89 views

Print AWK ou GREP in table format

How can I organize a command to print the results like this: USER | PACKAGE | CREATOR result - result - result result - result - result result - result - result I want to fetch these results ...
0
votes
3answers
69 views

Help with text formatting

I need help with bash scripting. Below is my input: Grp: MG1 user1 user2 user3 Grp: MG2 user7 user1 user9 user6 user2 The result should look like: Reporting MG1 MG1,user1 MG1,user2 MG1,...
0
votes
1answer
25 views

How to add a string on the beginning of one column and end of another?

I have a file like this: head pheno_143 FID IID CURRELIG RET_Summary new143 fam1000 G1000 1 1 1 fam1001 G1001 1 1 1 fam1003 G1003 1 2 2 fam1005 G1005 1 1 1 fam1009 G1009 1 1 1 fam1052 G1052 1 1 1 ... ...
0
votes
1answer
38 views

I would like to analyze a TXT file, but the data is a 1 column array, and it needs to be a in a multi-column array

Is there a way for me to manipulate the data (i.e.; change some feature of, so that it looks like it should, a multi-column array) without having to manually go through it? There are thousands of rows ...
-1
votes
1answer
64 views

What are some types of text files that shouldn't end with newlines?

This question and this question point out that generally the standard is to end text files with newline characters to meet the POSIX standard, and this is something expected with GNU tools and other ...
0
votes
0answers
59 views

How to ensure that list order stays the same, when lines are missing?

I run into a problem and can't wrap my head around it. Any help is welcome. Example Correct order, given or in external file: red blue green brown black Input: red blue green black Output: red ...
-1
votes
2answers
54 views

Capture only the file name from the directory Path [closed]

Requirement Col1 , Col2 , Col3 , Col4 1 , a:/b/c/abc.txt , f:/b/c/abc1.txt , a:/b/c/abc6.txt 2 , b:/bd/a/s/3/d/mon.dat , g:/b/c/abc 2.txt, b:/b/c/ab7....
0
votes
1answer
35 views

Regex within awk from txt file with one line

I am currently working on a script to wipe hard drives. The first script is already working and checks if there are new hard drives available. If there is a new disk available it will list it in a ...
1
vote
7answers
88 views

I have a csv file with a field having data enclosed in “ ” and commas in between. I want to replace it with another

Below is the first 5 lines of my file. Here, I want to replace the "10,00,000.0" of 5th column with "10,000,000.0". DE000A2200V7,09:30:00,8.5,8.509,"10,00,000.0","10,00,000.0","850,450.0" ...
2
votes
7answers
396 views

Replacing commas in text file with vertical line, except for in quotes [duplicate]

I have a txt file: ,"Hi, I am Tom",,"16" "I3","Hi, I am Jerry","Mouse","17" in which the file is UTF-8. What I'm trying to do is to replace the commas with | except for the ones in quotes "". So ...
0
votes
6answers
54 views

How to print a dynamic string with precedence - one liner

So I want to construct a command that would print a dynamic string with precedence. I have variables: a=first b=second/third/fourth/... I want to run sed command on b sed -e 's/\//_/g' and I ...
0
votes
2answers
68 views

align text bash script

I'm writing a script that will check the many applications services. I have the script looping through the services. Just looking for the best way to align the output text. Here is the code: ...
0
votes
2answers
71 views

sed add first word from previous line to beginning of the next line, if

I ran into a problem and can't find a solution to fix the following issue. I want to copy the first word of a line to the beginning of the following n lines if they start with a special character, ...

1
2 3 4 5
10