Questions tagged [text-processing]

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.)

Filter by
Sorted by
Tagged with
927 votes
8 answers
2.0m views

Find and replace text within a file using commands

How can I find and replace specific words in a text file using command line?
Jon Doe's user avatar
  • 11.4k
14 votes
8 answers
37k views

How to remove particular words from lines of a text file?

my text file looks like this: Liquid penetration 95% mass (m) = 0.000205348 Liquid penetration 95% mass (m) = 0.000265725 Liquid penetration 95% mass (m) = 0.000322823 Liquid penetration 95% mass (m) ...
O.E's user avatar
  • 251
18 votes
7 answers
64k views

How to find lines matching a pattern and delete them?

In a file with lots of lines I want to delete lines that starts with HERE IT IS. How can I do this using only command-line tools?
micgeronimo's user avatar
12 votes
2 answers
4k views

Tool to insert text snippets into applications

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 ...
guettli's user avatar
  • 1,737
24 votes
2 answers
77k 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 ...
Iker's user avatar
  • 345
176 votes
7 answers
416k views

How to find a text file which contains a specific word inside (not in its name)

I want to find a text file in my hard disk which contains a specific word. Prior to Ubuntu 12.4 I used to start in the dash an application, I think it was called "Search for file...", whose icon was ...
SomeoneMe's user avatar
  • 1,761
27 votes
6 answers
4k 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?
Avio's user avatar
  • 2,986
21 votes
8 answers
88k views

How can I print multiline output on the same line?

Is there a method to print multi-line output (single output) on the same line? For example, if the output is: abc def qwerty Is it possible to print: abcdefqwerty
Shrinidhi Kulkarni's user avatar
17 votes
7 answers
4k views

How do I retrieve only the needed line from terminal output?

I want to get only let's say third line of df -h output. What kind of command should I use?
emrecnl's user avatar
  • 860
64 votes
7 answers
220k views

Grep searching two words in a line

I've been trying to find a way to filter a line that has the word "lemon" and "rice" in it. I know how to find "lemon" or "rice" but not the two of them. They don't need to be next to the other, ...
Sebastian's user avatar
  • 745
22 votes
5 answers
18k views

How can I merge files on a line by line basis?

cat file1 foo ice two cat file2 bar cream hundred Desired output: foobar icecream twohundred file1 and file2 will always have the same amount of lines in my scenario, in case that makes things ...
TuxForLife's user avatar
  • 1,305
15 votes
11 answers
80k views

Remove the first part of a string using sed

How do I get from this: randomcollege-nt\user90 to this: user90 using sed?
Roboman1723's user avatar
  • 2,913
7 votes
9 answers
9k views

How to sort by row from terminal

I was looking at this question and I wondered if the following could be done from terminal. I did it in python, just want to see if it could be done from terminal, bash scripting or whatever. ...
Lynob's user avatar
  • 6,665
2 votes
1 answer
1k views

apache2 : How to search a string from apache2 error logs in specific time range?

I have logs like this , I want to search the string Form1Debugging from date [Sun Oct 01 04:26:29.593869 2017] to [Tue Oct 03 04:26:29.593869 2017] [Tue Oct 03 04:26:29.593869 2017] [:error] [pid ...
Haroon's user avatar
  • 211
109 votes
5 answers
406k views

How do I fetch only numbers in grep?

I have file like this : other lines . . . blah blah blah (:34) I wish to find the occurrence of numbers in the above file. I came up with: grep [0-9] filename But that is printing the whole: ...
Ant's's user avatar
  • 3,880
101 votes
8 answers
375k views

How to remove lines from the text file containing specific words through terminal?

How to remove all the lines from the text file containing the words "cat" and "rat"?
PersonX's user avatar
  • 1,087
37 votes
6 answers
139k views

How to replace spaces with newlines/enter in a text-file?

I have simple text file named "example". Reading with terminal command: cat example Output: abc cdef ghi jk lmnopq rst uv wxyz I want to convert (transform) into following form: (expected output ...
Pandya's user avatar
  • 35.7k
23 votes
5 answers
68k views

How to replace a string on the 5th line of multiple text files?

I want to replace the 5th line of multiple text files (file1.txt,file2.txt,file3.txt,file4.txt) with the string " Good Morning " using a single terminal command. All the text files are located on my ~...
Avinash Raj's user avatar
  • 78.5k
13 votes
1 answer
10k views

Why has gnome-search-tool gone?

It appears the gnome-search-tool is not available in Bionic. On https://launchpad.net/ubuntu/bionic/amd64/gnome-search-tool/3.6.0-2 it says status Deleted. I've downloaded the deb from Wily Proposed ...
user17254's user avatar
  • 613
10 votes
7 answers
27k views

Concatenate two files and separate them with a newline

I have two files: k.txt: 3 5 7 9 19 20 h.txt: 000010 100001 111001 if I just use cat, there is no newline. I need a command which would provide a file which looks like this: 3 5 7 9 19 20 ...
user3069326's user avatar
7 votes
1 answer
1k views

How can I verify the integrity of an mbox archive from the command line?

I have a large mbox file backup from gmail. It's over 5GB, and gets updated with new messages every night via a cron job. I would like the cron job to also check the validity of the archive, to make ...
Chase Seibert's user avatar
6 votes
2 answers
12k 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 ...
Hassen Fatima's user avatar
6 votes
2 answers
7k views

How to cat file with limit of printed characters from each line?

I would like to cat file, but with limit to max length to each line. For example I a have file with 10 lines each have 10000 characters and I would like to print first 100 characters from each line. ...
Martin877's user avatar
6 votes
4 answers
25k 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 I ...
Lynob's user avatar
  • 6,665
6 votes
6 answers
8k views

How do I remove lines of a file which contain a specific string?

How do I remove lines of a file (hosts) which contain "adf.ly" string?
wb9688's user avatar
  • 1,437
5 votes
3 answers
6k views

ASCII source file checker

For official Ubuntu documentation where the source English files are in docbook xml, there is a requirement of ASCII only characters. We use a "checker" command line (see here). grep --color='auto' -...
Doug Smythies's user avatar
4 votes
4 answers
270 views

I need to use sed/awk to get desired output

Order:479959,60=20130624-09:45:02.046|35=D|11=884|38=723|21=1|1=30532|10=085|59=0|114=Y|56=MBT|40=1|43=Y|100=MBTX|55=/GCQ3|49=11342|54=1|8=FIX.4.4|34=388|553=2453|9=205|52=20130624-09:45:02.046| ...
Sonal's user avatar
  • 47
4 votes
1 answer
3k views

Find and delete a line that starts with a certain string in a file

My file currently has Name. Address. Phone number Jack. L.A 1435672 John L.A. 1465432 Nick. F.l. 1489756 When the user wants to delete ...
Abdulaziz Yesuf's user avatar
4 votes
4 answers
16k views

How to delete specific lines from a txt file

I have a Bash script that writes data into a log file, then from that I take out stuff I want using the sed command. That gives me a file data.txt. What I want to know is how I go about deleting ...
Insanebench420's user avatar
4 votes
1 answer
456 views

Search and replace a pattern containing backslashes

I have a file bla bla bla bla bla bla bla bla bla bla bla bla bla bla \newcommand{\datestamp}{20180215} bla bla bla bla bla bla bla bla bla bla bla bla bla bla I need ...
Aristocrat's user avatar
3 votes
3 answers
5k views

How to get values after an equal sign

I have a file delimited with space and random column ordering as follows: name=Joan age=42 ip=172.20.1.80 sex=M loc=UK loc=IR sex=F ip=172.20.1.1 age=32 name=Sandra I want to extract specific ...
Ubai salih's user avatar
3 votes
5 answers
2k views

Join two files, adding values in certain columns

How can I add another 2 values after matching the values from 2 columns in another file just like VLOOKUP? Sample below. Value in column 6 & 7 from file1, when matched with column 1 & 2 from ...
pawana's user avatar
  • 115
2 votes
2 answers
37k views

How would I edit a .conf file without gedit from the terminal over SSH?

I guess my question is closer to "How would I go about editing a .conf file from a remote connection via an ssh terminal?" I downloaded an ssh emulator to my iPhone which works fine and dandy, and I ...
brooke's user avatar
  • 83
2 votes
4 answers
838 views

how to separate each content in the file?

I have a text file (more then 1GB in size) and it contains lines like these: ...
maa's user avatar
  • 91
2 votes
3 answers
469 views

Somehow I created a nondeterministic sh script

I created the following script: #!bin/bash cat > Top10 <<EOF Linux Mint 17.2 Ubuntu 15.10 Debian GNU/Linux 8.2 Mageria 5 Fedora 23 openSUSE Leap 42.1 Arch Linux CentOS 7.2-1511 PCLinuxOS ...
Grg's user avatar
  • 33
1 vote
1 answer
121 views

How can I extract records from a file if they include a specific set of strings?

I am analyzing a file xyz.txt which contains hifen separated records. I want to extract records based on the presence of the strings FADED:100, AM:FF and GG. Subsequently, I need to write them to a ...
shekhar's user avatar
  • 807
1 vote
1 answer
1k views

searching for specialized patterns using grep in a json file

I wonder how can I only grep the "created_at": ones that are followed by }, and a new line like below: "hashtags": [], "urls": [] }, "created_at": "Wed Oct 19 22:19:42 +0000 ...
Mona Jalal's user avatar
  • 4,545
1 vote
1 answer
516 views

How can I use the grep --color command to highlight brackets?

I want to highlight every [ in any color so i can see the hidden message here: [###[#[[[#[###[#[[[#[[[#[###[#[[[ [###[##[##[[##[#[####[##[[##[##[# [######[##[#[#[#[[[##[##[#[#[##[# [######[##[##[[#[#...
Jena Alissa's user avatar
0 votes
2 answers
256 views

Something with .txt File? [duplicate]

I have stored a text as .txt while saving it in Gedit in Ubuntu 14.04. But after viewing that folder, which i have stored will have two files with that name but with 'Tilde Symbol' '~' for an ...
Madhusudhanan's user avatar
0 votes
1 answer
193 views

How to import an mbox file into the Pine or Alpine mail client?

I'm a light Alpine e-mail client user. If I navigate into ~/mail and run mail -f baz I'll get an expected list of old alpine/pine messages. Alpine doesn't use mbox. I added an mbox backup to that ...
Nicholas Saunders's user avatar
155 votes
13 answers
409k views

How to compare two files

I want to compare two files line by line and by column number 2. How could I accomplish this? File_1.txt: User1 US User2 US User3 US File_2.txt: User1 US User2 US User3 NG Output_File: User3 has ...
Roboman1723's user avatar
  • 2,913
104 votes
5 answers
444k views

How to separate fields with space or tab in awk

While playing with awk I came to execute: ls -la >> a.txt ; awk {'print $5 $1'} a.txt ; This is giving output like: 53277-rw------- 52347-rw------- How can I get a space between these two ...
Raja G's user avatar
  • 102k
51 votes
4 answers
286k 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 ...
Buddha's user avatar
  • 529
33 votes
8 answers
26k views

Prepend ## to every line in a text file

I want to add hashes to all the lines in a regular text file. I'm fine with both the use of terminal and GUI—I just need to get it done.
Oxwivi's user avatar
  • 17.8k
22 votes
8 answers
24k 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. ...
Oli's user avatar
  • 293k
13 votes
6 answers
11k views

Print a specific part in an output

Let us suppose that there is a command such as: cat /boot/config-3.19.0-32-generic | grep CONFIG_ARCH_DEFCONFIG The output is as such: CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig" Now,...
Raphael's user avatar
  • 8,035
11 votes
6 answers
14k views

How to convert from row to column?

I have a .txt file with numbers ordered like this (on the same row): 106849_01373 106849_01967 106850_00082 23025.7_01059 I would like to convert them like that: 106849_01373 ...
Annemieke Smet's user avatar
11 votes
6 answers
2k views

How can I get bash/zsh to change some text from "foo.foo.foo" to "foo foo foo" with a script/alias?

I can maybe use < or > or |. Maybe I need to use grep?
K.D.G's user avatar
  • 151
11 votes
3 answers
2k views

Compare source code files, ignoring formatting differences (like whitespace, linebreaks, ...)

I am looking for an application that can compare two C++ sources and find the code-meaningful differences (to compare versions which may have been reformatted differently). At the very minimum, ...
sancho.s ReinstateMonicaCellio's user avatar
9 votes
4 answers
43k views

Replace or add a string to a file

I know sed can replace a piece of string within a text file like this : sed -i 's/oldstring/newstring/g' test.txt But, how do I replace the line if it exists and automatically add it on a new line ...
Josh's user avatar
  • 221