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

6
votes
8answers
197 views

Access individual lines of a text file and create separate text file with that name

I have two text files (say text1.txt and text 2.txt) both with same number of lines. Ex. text1.txt contains 4 entries 0127H 0132H 0982H 1772H text2.txt contains 4 entries stev mary beautiful ugly ...
1
vote
3answers
58 views

Edit text iteratively within a file using commands

I am a new Ubuntu user. Please help me in solving the following problem: My input text file is -0.716425 -12.8939 -3.3341 -7.38497 -2.62709 3.00437 -6.69861 -13.8853 -5.81095 -7.37465 ...
2
votes
2answers
71 views

How to delete all lines before and after the specific strings in the file?

I have played with Powergrep and regular expressions but I don't know how to do that: I have the text file (source code of webpage) and I want to delete all text (a lot of lines) before the specific ...
3
votes
4answers
66 views

Replace string with multiline file content

I need to replace string SALT in a file with content of another file. Problem is that the input file has multilines. I tried something like this in my bash script: SALT=`cat salt.txt`; sed ...
0
votes
2answers
20 views

How do you create a process list ''file'' like process.txt on windows?

I would really like to know whether there is something similar to process.txt on ubuntu. You know, an overview of all of your processes as a text-file in order to E-Mail it to others or load it on an ...
3
votes
3answers
199 views

How to label occurences of text?

I would like to convert blue blue red green to: color.1=blue color.2=blue color.3=red color.4=green Any leads on how to tackle this? sed, awk, etc.?
1
vote
1answer
28 views

Command-line perl regex replacement: replacement string contains utf8

Say you have a file named test.txt with the following lines: ಕದಂ.ಬ कदम्ब. Then, suppose you want to replace each dot following a devanagarI unicode character (ie in कदम्ब) with a ।. Then, you might ...
2
votes
1answer
106 views

copy several lines from one file to another

I would like to use grep in order to copy from one file to another all lines that are between lines /protein_id= untill the end of the protein sequence shown. For example, from this input: CDS ...
1
vote
1answer
52 views

Find and replace regular expression (matching unicode character class Devanagari) in multiple files

Say you have a file named test.txt with the following lines: ಕದಂಬ कदम्ब Then, suppose you want to replace each devanagarI unicode character (ie in कदम्ब) with a D. Then, you might think that the ...
4
votes
2answers
235 views

Print only one line at a time from text file

how can I print or display only word from a text file at a time. When I run my script it should only display each word from the text file one by one, but only display that word. This is what I have ...
3
votes
4answers
71 views

How can I divide output with delimiter?

I would like to change: e·ver·y·bo·dy to: e·ver·y·bo·dy e·ver·y·bo· e·ver·y· e·ver· e· A for loop will be greatly preferred.
5
votes
7answers
272 views

split a file based on pre-defined set of rows

I want to split a text file according to a pre-defined set of rows. For example. I have a file a b c d e f And then I have the following sets of rows (these could be stored however it is more ...
0
votes
1answer
46 views

Custom terminal function to change text case

I'm looking for a custom terminal function change_case that will function as below to help me manage my titles on my website: change_case [option] "string" option: upper - STRING TO UPPERCASE ...
7
votes
11answers
994 views

How to count occurrences of each character? [closed]

For example I have file 1.txt, that contain: Moscow Astana Tokyo Ottawa I want to count number of all char as: a - 4, b - 0, c - 1, ... z - 0
1
vote
1answer
41 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
118 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
603 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
73 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
73 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
96 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
35 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
837 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
64 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
269 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
39 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
52 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
2k 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 ...
7
votes
3answers
605 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
1k 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
786 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
347 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
188 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
90 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
258 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
59 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 ...
3
votes
5answers
2k 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
80 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
436 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
90 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
2k 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
87 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
102 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
72 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
349 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
158 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
391 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
895 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
5k views

Remove the first part of a string using sed

How do I get from this: randomcollege-nt\user90 to this: user90 using sed?