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

2
votes
2answers
150 views

Combining 2 commands

I need to write a shell script for converting characters in a file to lowercase and replace non alpha chars to _. I have separate command for both the above. How to give a file as argument and make ...
2
votes
1answer
99 views

Based on certain patterns exclude lines in file [duplicate]

My file looks like this [0.00137532,[0,13,19,16,18,15,19,16,11,15,12,12,13,14,0,11,17,18,14,17],[0,0,0,0,0,0,0,0,0,0,0,0.0189924,0.0871235,0.179813,0.307779,0$ SITE: 0 0.000853196055 0....
0
votes
1answer
40 views

Replacing a variable permanently in shell [duplicate]

I have file <temp_test.sh> in which I have defined a variable Min_Inc=300000. I then want to get the user input to change the value of Min_Inc. I followed these steps. Read the value using ...
1
vote
1answer
27 views

show a group of specific lines from all files with .txt extension

How can I print specific lines (say the 7th to 15th) of each file in the current directory whose name ends in .txt? I Know About 7 and 15 it is done like awk 'FNR==7 || FNR==15' *.txt but if i ...
1
vote
1answer
46 views

show specific lines from all files with .txt extension

How can I print specific lines (say the 7th and 15th) of each file in the current directory whose name ends in .txt?
4
votes
4answers
102 views

How to capture lines between two strings from a file, but only the last occurrence?

I have a log file which is output by a script, the log file is rotated daily. It will contain the strings Transfer started at timestamp and Transfer completed successfully at timestamp ...
15
votes
7answers
1k 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?
-1
votes
1answer
42 views

Display all the lines which ends with the word “unix” or specific word in terminal [duplicate]

How to display all the lines which ends with the word unix in any given file and sorts those lines in ascending order.
6
votes
4answers
343 views

How to add the text before the line in whole file?

I have list of domain in text file and I need to add 127.0.0.1 ip before the line in whole file. Example as below: domain.txt .... abc.com ... I want to generate HOSTS file like ... 127.0.0.1 abc....
0
votes
2answers
68 views

Add lines from file to another file

I have two files. First file (users.txt): !/bin/bash/ johnny james clara brandon steve louis daniel Second file (mails.txt) [The first line is not empty, the file contains only mail ...
2
votes
2answers
51 views

How to print a line that is followed by a specific string in a repetitive file?

This is my first question and I hope you can help me. I've search how to do this but haven't found a solution. I have a text file with thousand of repetitions like this one: Query= AX-1 [some ...
0
votes
0answers
28 views

Update URLs in one file with URLs in another file

I have a local text file that, among other things, contains a list of URLs that expire periodically. There is a file on github that I can pull on occasion that has the updated URLs. Each of those URLs ...
0
votes
1answer
57 views

How to extract a rectangle of text from a file in CLI?

Huge note: I AM NOT TALKING ABOUT TEXT EDITORS! I need to extract (stdout is OK) a rectangle of text from a text file. A rectangle should be the text between lines l1 and l2 and columns c1 and c2. I ...
0
votes
2answers
37 views

bash script to run a second command with select output from first command as variable

I'd like to get the output of the second command with the 7 character PSI domain (00:01.0) as a variable. How can I write a bash script to do this? jeff@jeff-probook:/$ lspci | grep VGA 00:01.0 ...
1
vote
3answers
88 views

How can I extract pdf names from an lftp log file?

I have a log like this : 2016-05-11 07:09:54 ftp://test@test.dyndns.info/test1/fool/1999/How/05%20May/test160511.pdf -> /test/keep/more/use/05/test160511.pdf 0-28442281 33.5 KiB/s i need to ...
0
votes
1answer
73 views

How can I get and change a value of a line inside of a file if the value of such line is unknown by me?

What I am trying to do is: There's a file, inside of it, there's a line (it surely will be there, 100%) in this model: name_of_the_value=xxx Where the value is numerical and unknown by me because ...
-1
votes
3answers
44 views

UNIX -grep 2nd character

So here's a sample line in my script: echo "Enter time(MILITARY FORMAT)(i.e 1245): " read time` so for example the user's input is 1315 how do i grep the 3rd and 4th digit (15) and then the output ...
6
votes
8answers
414 views

How to remove brackets () around ip address from traceroute output

I need to extract the 2nd IP address from a traceroute like so traceroute -m2 8.8.8.8 |grep .net |awk '{print $3}' (111.222.333.4444) No matter what I try I can't seem to work out how to remove the ...
3
votes
3answers
174 views

How do you extract a particular column or row from the output of a command?

Example: abcd@abcd-abcde:~$ xinput --list --short Virtual core pointer ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)] ↳ Logitech USB RECEIVER id=12 ...
3
votes
3answers
90 views

How to remove XML-like tags from input?

I'm updating my .bashrc file to show weather I'm using the line lynx -dump "http://wxdata.weather.com/wxdata/weather/local/14225?cc=*&unit=f&dayf=1" | grep -A 2 -m 1 "<tmp>" Which ...
0
votes
1answer
44 views

printing distances of desired character based on occurance

This is an extension of my previous question (Printing pattern of "C" character). I would like to print "C" character from "text" column given in file.csv. The file.csv has two coloumns as ...
2
votes
1answer
60 views

How to use sed with file path variables AND regex callbacks AND arithmetic expressions

I'm having a hell of a time getting the proper syntax using sed with variables containing a file path, a regex callback and an arithmatic expression. I don't know how to properly escape things. I ...
1
vote
1answer
25 views

how to replace 3rd row in a file using sed?

I need to change a variable in a file using a bash script, i think sed is the way to go but i can't figure out the regular expression. I have tried replacing a character in the file but then ...
0
votes
0answers
35 views

Mass delete of emails from text file found in word document

I've got two files. The first file is about 700 email address that I have in a text file, the second file is my complete email list which includes first name, email address. What I need to do is do ...
1
vote
2answers
56 views

Get unique lines from log using grep and tail

I have the following log file. I want to extract the last 10 unique entries from this file. Is it possible to do with grep and tail? 2016-04-18 10:13:11,925 (glastopf.glastopf) 115.239.248.245 ...
1
vote
1answer
23 views

How to replace string containing file path using sed

I want to replace a file path to other using sed. I am attaching a small part of my file Kindly help source file : Dir=D:\test\foo Dir=D:\test\bar the result should look like this Dir=E:\test1\...
3
votes
5answers
348 views

How do I merge tab-delimited files?

I have 3 tab-delimited files as shown below: File 1: 1 Hhe.7 2 Hpyl.1 10 Hac.2 File 2: 3 Hac.2 15 Hpyl.1 33 Hhe.7 File 3: 70 Hpyl.1 23 Hhe.7 9 Hac.2 How do I merge these files (...
3
votes
5answers
534 views

How do I transpose a row to a column in a tab-delimited file?

I have a tab-delimited file with a number and the names belonging to the same number on the same row. The number and names are separated by a tab. The names are linked with each other by 2 underscores ...
0
votes
3answers
202 views

How to remove all but number from hexdump output?

I have got the base64 output for a huge file, the output is also obviously huge and in a file of its own, I wanted to convert the big number in it to base10 so I have now used hexdump to get it into ...
0
votes
2answers
34 views

Replacing a Substring with sed

So I've got a line that looks like this ish somelongbullshit:888:morelongbullshitthatcanhaveanything And I want to replace the second : with a tab character. I can reliably match the substring I ...
2
votes
1answer
45 views

How do I use variables and non-variables in a single sed command?

I'm trying to use sed to replace some PHP lines. My problem is I want to replace a line with PHP variables with a string including a Bash variable. Here is an example: sudo sed -i 's/$sUrl . $...
2
votes
3answers
243 views

String replacement with iterator

I have a file with a character I would like to replace, but I also want to have each instance of the character(s) to be replaced, be iterated with a number inside the sting replacement. SomeFile.txt ...
2
votes
4answers
182 views

How do I join two CSV files but only where 2nd file matches?

I have 2 CSV files: Objects File: IP,MASK,DESCRIPTION 10.10.3.94,255.255.255.255,Rob 10.10.3.95,255.255.255.255,Mark 10.10.3.96,255.255.255.255,John Services File: DESCRIPTION,OrgIP,Service Rob,1....
2
votes
1answer
44 views

How to delete multiple lines from txt file, based on a variable in previous column?

The idea is this: I have a document with data listed in the following way (shown below), and I want to delete any line that has a value of 70 or less in the 6th (last) column. On top of that, I want ...
1
vote
2answers
226 views

Crop a string using sed

I have a command that outputs me a list with the following pattern exp_70_T8_s1 exp_71_T8_s5 exp_72_T8_s10 exp_73_T10_s1 exp_74_T10_s5 exp_75_T10_s10 ... How can I get the numbers after "_T" and "...
-1
votes
2answers
78 views

Joining 2 files and comparing them [closed]

I have two files where I want to use something like a left join that is used in SQL. File1: column1 column2 column3 column4 Ab Cd 100 Us Ef Gh 200 Us File2: ...
1
vote
1answer
34 views

Replace text in one file and match in second file

I have two text files, file1 and file2. In file1, I would like to start the numbering in the second column (after the space) from 0. However, this new numbering should match the numbering in file2. ...
4
votes
3answers
295 views

grep command for a text file in multiple directories

I have 24 directories in a specific directory (main_directory). Each 24 directory have a text file whose name is DATA.txt. I need to use grep command to extract below specific pattern for each text ...
1
vote
2answers
92 views

remove special character using sed

I have a text file that contains following https://git.centos.org/git/rpms/abc.git https://git.centos.org/git/rpms/abc.git/ https://git.centos.org/git/rpms/abc When I run the following command, ...
1
vote
2answers
224 views

How do I replace '<p>' with '<p>\n' and '</p>' with '\n</p>' using sed?

I have following file and I want to replace <p> with <p>\n and </p> with \n</p> using sed. My input file contains the following lines: <p>This is home.</p> <p&...
1
vote
2answers
214 views

Get a specific word using awk

I am coding a script to check mysql databases using bash script, I would like to check if the status of a table is not 'OK', will return the table name and do some more actions: check.log table1 ...
6
votes
5answers
1k views

Get one element of path string using bash

I have an ASCII file containing filepaths which I read by running: while read p; do echo $p; done < filelist.txt The file contains filepaths with the following pattern: ./first/example1/path ./...
9
votes
6answers
708 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 ...
1
vote
3answers
102 views

split txt file in half based on pattern

I have a text file which looks like this: train/a/abbey/00000001.jpg 0 ... train/a/abbey/00000999.jpg 0 train/a/abbey/00001000.jpg 0 train/a/airport_terminal/00000001.jpg 1 train/a/airport_terminal/...
0
votes
1answer
29 views

List all binaries a package provides

This is not a duplicate of listing all files a package provides, i want to list all binaries a certain package provides that are in the standard location for binaries. I know this can be done with ...
5
votes
2answers
150 views

Split file into two files when pattern appears using command

I want a simple command (either AWK, Perl etc.) to split the file into two files as shown below. test.pem: -----BEGIN PRIVATE KEY----- ...
0
votes
1answer
32 views

Suppress command output lines that contain a certain string

When I run an arbitrary command in the terminal in linux, is there a way to suppress output messages that contain a certain sentence? I tried ./mycommand | grep -v "I dont want to see this" but ...
1
vote
2answers
82 views

How can I get the last occurrence of a repeated string in the text file?

I have a data file consists of several rows and columns with numeric and string data. Some string and numeric patterns are repeated. I need to extract last repeated pattern. For example; 715 ANKR PRN ...
4
votes
2answers
100 views

How do I compare two files containing several md5 checksums to determine changed files?

I have two files MD1 and MD2. MD1 contains md5sums: 5f31caf675f2542a971582442a6625f6 /root/md5filescreator/hash1.txt 4efe4ba4ba9fd45a29a57893906dcd30 /root/md5filescreator/hash2.txt ...
-1
votes
3answers
40 views

How to get specific portion of a command result?

From the result of this command: diskutil info / | grep "Free Space" which is something like this: Volume Free Space: 31.5 GB (31519584256 Bytes) (exactly 61561688 512-Byte-Units) I want ...