Questions about modifying, creating or parsing plain text files. This is a very broad tag, if your question is about using a specific tool, please tag it with the tool's name as well (e.g. sed, awk, perl, etc.)

learn more… | top users | synonyms

-3
votes
1answer
41 views

How to find and replace a particular string in the following manner

My input file is, ami0041 ami00056 ami0029 ami023 ami0099 ami049 ami00999 tumi0234 bichi23455 susami345 Using a single command line I need the output as, ami0042 ami00057 ami0030 ami024 ami0100 ...
-2
votes
0answers
45 views

How to replace first string before first space [on hold]

NC_009925.1_13653 [754389 - 754574] Acaryochloris marina ATTCCTGATTCTCTTGATGAAAGTAACATTATGGATCAT... TATGATCCATTCAGGCATGATGCAAGGCGCTACCCCCAA... 110311 2992101 2992319 len=219 ...
1
vote
1answer
26 views

How do I 'cat' a text file but start from the bottom instead of top

I have a very big text log file of about 37MB. Using cat file | more I can view the file contents one page at a time. The problem is that this always starts from the top - the old entries. How can ...
1
vote
2answers
91 views

Grep strings in a subgroup of lines in txt file

I have a file that looks like this AAA_21 PF13304.1 x_00004 AAA_22 PF13401.1 x_00004 SMC_N PF02463.14 x_00004 AAA_29 PF13555.1 x_00004 ...
2
votes
1answer
117 views

bash comparing multiple column in two files with different length

I have following data set in text file data.txt d1,40,gold d2,30,silver d3,20,bronze d4,10,iron d5,5,wood d6,20,gold d7,10,wood d8,5,gold d9,10,silver . . . def.txt gold,40 silver,30 bronze,20 ...
1
vote
1answer
54 views

How to replace word occurrence in ranges specified using sed command?

str="I want to abc replace a word abc in a sentence abc of file abc by giving abc specifying a abc multiple abc range to abc the sed abc command abc." The above sting str has word "abc" 10 times ...
1
vote
2answers
43 views

How to print both matching lines from two different files? [duplicate]

I have file1 and file2 as following. I would like to first find matches between two files based on first column and then print the matching lines from file1 and file2. I have written the desired ...
0
votes
1answer
43 views

Bash Script - Editing Lines on Text From File

I'm using a bash script to read in data from a text file. #!/bin/bash file="/home/nexusfactor/Desktop/inputData(linux).txt" while IFS= read -r line do # display $line or do somthing with ...
-1
votes
2answers
29 views

interchange 2 strings in file terminal command

I want to swap 2 strings in a file Here is the example [ link ]( text ) I want to make it [ text ]( link ) how can i do this ? i tried something with while but i can't make it link = ...
7
votes
6answers
792 views

How can I get lines where a specific word is repeated exactly N times?

For this given input: How to get This line that this word repeated 3 times in THIS line? But not this line which is THIS word repeated 2 times. And I will get This line with this here and This one A ...
0
votes
2answers
44 views

Bash: Regular Expressions in substitution

I have a bash script to substitute number values inside a text pattern. Suppose I have a file like this: word5word word55word And I want it to look like this: word125word word125word I have this ...
0
votes
2answers
138 views

How to use sed to find the strings between 2 patterns?

I have file content like this: aaa accounting exec ... aaa accounting exec ... aaa accounting commands .. aaa accounting commands .. aaa accounting commands .. aaa accounting commands .. aaa ...
1
vote
2answers
30 views

Append line numbers at end of each line in the file

In a peculiar case I needed some of my text files to append with line number at the end. How to achieve this?
1
vote
1answer
38 views

Are there NLP tools for text analysis?

Are there any tools on Ubuntu that can be used for Natural Language Processing? I am not necessarily looking for R, python or java scripts (thought they could be valuable), but for command line tools. ...
2
votes
1answer
953 views

How do I grep for multiple patterns on multiple lines?

To be precise Some text begin Some text goes here. end Some more text and I want to extract entire block that starts from "begin" till "end". with awk we can do like awk '/begin/,/end/' text. How ...
6
votes
3answers
510 views

How to grep lines, based on a certain pattern?

Let's say I have a file containing following two lines: 2014-05-05 09:11:53 /aa/bbbb/cccccc 29899 2014-05-05 09:12:17 /aa/bbbb/cccccc?dddddddd 16767 I need to get ...
4
votes
4answers
646 views

How to find all patterns between two characters?

I'm trying to find all patterns between a pair of double quotes. Let say I have a file with contents look like as following: first matched is "One". the second is here"Two " and here are in second ...
2
votes
4answers
522 views

Comparing two text files

I have 2 big csv files, file1.csv which looks like this 1,2,3,4 1,4,5,6 1,7,8,9 1,11,13,17 file2.csv which looks like this 1,2,3,4 1,7,8,9 2,4,9,10 13,14,17,18 These are just random numbers that ...
22
votes
4answers
2k views

How to “cat” or “less” a libreoffice writer .odt file?

Is there a way to cat or less a .odt file just as antiword does for .doc files?
1
vote
4answers
209 views

extract text from a file using terminal?

I want to process the body of text and extract an integer from a specific position in the text, but I'm not sure how to describe that 'particular position'. Regular expressions really confuse me. I ...
1
vote
1answer
100 views

Printing footers using enscript

I have a working bash script which converts text files to postscript using enscript 1.6.5.90-2 on Kubuntu 14.04. It does several other things to make the output look better like setting margins, ...
1
vote
1answer
83 views

Insert text blocks everywhere

In german you start mails and letters with "Sehr geehrter Herr ....". I am tired of typing this again and again. And I am tired of configuring applications to give me shortcuts to insert text blocks ...
5
votes
3answers
231 views

How to compare output of a running process?

I am running a benchmark on gem5 simulator, which keeps printing output to terminal while its running. I already stored a sample run of the same benchmark in a text file. So now I want to compare the ...
0
votes
1answer
54 views

How can I make a script for opening a predefined set of .txt files on gedit at startup?

Unfortunately as of late a lot of gedit plugins have stopped working for me, including the session saver. I wanted to find an easy solution to this problem and then it came to me that I can just ...
2
votes
5answers
961 views

How to transform valid JSON to CSV?

I'm trying to extract information from a JSON file and write some of the contents to a CSV file. Here is an example of my text "data":{"headers":{"sender":"frank@abc.com" "to":"jim@def.com" ...
2
votes
2answers
79 views

Sed matching problem, output not as expected

What I need to accomplish: I want to recursively match everything from string1 to fixed_string (both included) on text_files and output the results onto a result_file. My command is as follow: sed ...
5
votes
2answers
330 views

How to save matched pattern into variable using 'sed' command?

I'm trying to find a pattern using sed command in file.txt between first char1 and char2 and then replace that with string. like below with echo mode example: echo "This X is test Y. But X is not ...
1
vote
3answers
77 views

csv file adding and removing characters from rows [closed]

I have a big csv full that looks like so else if(a,b,c,d,e) else if(a,b,c,d,f) I want to make it look like so else if(a+x==b and b+x==c and c+x==d and d+x==e) else if(a+x==b and b+x==c and c+x==d ...
1
vote
2answers
791 views

How to grep for groups of n digits, but no more than n?

I'm learning Linux, and I have a challenge that I seem to fail to solve on my own. Here it is: grep a line from a file which contains 4 numbers in a row but not more than 4. I'm not sure how to ...
2
votes
2answers
86 views

Change text in many files

I have a C++ project, where each file has at its beginning some lines of license. Now, that my license have changed, I need to update it in each file. I don't want to do it manually, since its lots of ...
1
vote
2answers
95 views

Looping through csv, removing patterns

I have a question similar to my earlier question, but a bit different say you have 10 columns on each line, and 100000 lines, I want to check if each row for the following patterns: If a row looks ...
1
vote
3answers
60 views

split string with a certain character to form a path

I have a string abc_d_e75_f10_xyz_l_11 I want to split it so that I want to construct a string of an existing directory from this string to cd to it. So in this example abc_d_e75_f10_xyz_l_11 I want ...
1
vote
4answers
257 views

using sed replace the new line with character

I am using sed command to remove the new line and replace with <br> but I am not able to get the desire output. I wrote : find . -name $1 -print0 | xargs -0 sed -i '' -e 's|\n|ABC|g' but ...
3
votes
4answers
155 views

How can I get the names contained in the first file that are not i?

I have two files containing billions of DNA sequence names, the second is a proper subset of the first: for example, 1°:john mike anna paul laura .... 2°:john mike paul ... all the names occupy ...
14
votes
5answers
2k views

How to display a random line from a text file?

I am trying to write a shell script. The idea is to select a single line at random from text file and display it as an Ubuntu desktop notification. But I want different lines to be selected each time ...
4
votes
5answers
350 views

Shorten lines, adding “…” ellipsis

How to cut off lines that are longer than some width, and marking the lines that were chopped off with an ellipsis? Only lines that were actually shortened should be marked, but not lines that had ...
8
votes
4answers
814 views

How can I repeat the content of a file n times?

I'm trying to benchmark to compare two different ways of processing a file. I have a small amount of input data but in order to get good comparisons, I need to repeat the tests a number of times. ...
9
votes
9answers
3k views

Remove the first part of a string using sed

How do I get from this: randomcollege-nt\user90 to this: user90 using sed?
2
votes
2answers
338 views

How do I get `tr` command to ignore newline?

I want to replace multiple spaces by a single space. I am using tr to do this. But it is also replacing new line with a space. How can I avoid it? Code: tr -s [:space:] ' ' Input: He llo Wor ld ...
0
votes
2answers
99 views

Sorting two columns with sort and uniq

I have a file that needs sorting in a specific way but I can't figure out how to do it. I've tried the following command but it doesn't give me what I want: sort -t" " -k1,1 Original_File | uniq ...
2
votes
3answers
639 views

Reverse all words in current line

I have a file and I want to reverse all word in it. ex input file: DCBA. HGFE.GI MLK,PON.RQ UTS. ZYXWV. 321 ex output file: (What I Want) ABCD. EFGH.IG KLM,NOP.QR STU. VWXYZ. 123 With this sed ...
0
votes
5answers
467 views

Compare strings in two files

I am trying to get the name of the user from one file and their corresponding details from my other file. I use awk: awk -F : '{ print $1 }' user-name it gives me the list of all the user's. So ...
4
votes
3answers
448 views

Searching for patterns in csv files

I have file.csv that looks like this 4,6,18,23,26 5,12,19,29,31 2,5,13,16,30 9,10,24,27,32 4,5,10,19,22 4,6,8,10,25 2,3,4,25,11 I want to find some patterns and save them in another log file ...
9
votes
4answers
502 views

How to delete words from txt file, that exists on another txt file?

File a.txt has about 100k words, each words is in new line july.cpp windows.exe ttm.rar document.zip File b.txt has 150k words, one word by line - some words are from file a.txt, but some words are ...
5
votes
2answers
374 views

Remove text that I don't want

I have a big html file on my desktop that looks like src="http://images.alaablubnan.com/images/Balls/20.jpg" ...
2
votes
2answers
181 views

How to add one column to the another file

suppose this is my file which its name is myFile1 1 10 2 20 3 30 4 40 5 50 6 60 know I want to add my another columns to this. This column is on the file which is myFile2. 10 11 12 13 14 15 16 . ...
4
votes
6answers
301 views

Bash script programming: how to match pattern in string?

How I can get this whole value 7I45432ZX from below lines: PW*3434*453*256*PE*UB PO*00*NE*7I4543 2ZX**20140617 PW*3434*453*256*PE*UB PO*00*NE*7I4543 2ZX**20140617 This is the code I tried: grep ...
3
votes
2answers
348 views

Find a word using AWK

Is there a way to find a specific record among the whole line? This is my file: one two three four two three four five three four five six four five six seven five six seven eight How do I search ...
1
vote
2answers
487 views

Get unique values and their counts in a column

I have a column like this. Streptococcus Ecoli Bcoli Ecoli streptococcus Streptococcus Mycobacterium Ecoli I want a file like this (which includes all unique values and their corresponding counts) ...
1
vote
2answers
6k views

Add/edit line text in file without open editor (linux command) [duplicate]

I know how to add new text to a file, but how can I edit it? Example: adding hello_world = 1 to test.txt using the following command: echo "hello_world = 1" >> test.txt But how can I change ...