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

0
votes
1answer
37 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
42 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
20 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
47 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
19 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 ...
3
votes
5answers
297 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
496 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 ...
1
vote
3answers
183 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
30 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
39 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
242 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
156 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 ...
2
votes
1answer
43 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
211 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
77 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
33 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
265 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
71 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
215 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> ...
1
vote
2answers
199 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
805 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
703 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
79 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 ...
0
votes
1answer
21 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
144 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
27 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
41 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
93 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 ...
0
votes
1answer
25 views

How to delete all `uuid=“*-*-*-*-*”` attributes in an XML file using the terminal?

Here is my code in myfile.jrxml. All I want to do is to delete all the uuid="contained_value" attributes. I've searched them with grep -ir uuid *. How to delete them? <band height="50"> ...
3
votes
2answers
87 views

Run shell script to take output of a file and convert it into Excel format

I have data in two different files called test1.txt and test2.txt, like: ID : 1 Name: xxxx Age: 33 Education: Mtech ID: 2 Name: yyyy Age: 22 Education: bsc I want to print these lines using a ...
0
votes
2answers
35 views

searching about specific word in a Directory then delete it

I search in a directory for a given word in text files by this shell script instruction grep -r "$2" "$1" $2 is the directory $1 is the word How can I delete this word after it?
1
vote
1answer
412 views

extracting information from file

I have a file like: number_of_x 100 # total number of x number_of_y 2000 # total number of y total_rate 1.67 # rate blah1 0.876 # blah1 blah2 10450 # blah2 I would like to ...
3
votes
1answer
141 views

Sort file/folder output in Bash

I have output like this (alphanumerical): bash /etc/file bash /etc/filenew bash /etc/skel/ bash /etc/skel/file bash /etc/skel/filenew bash /etc/skel/new/backups/ bash /etc/skel/new/file bash ...
0
votes
1answer
30 views

change format table in ubuntu [closed]

There is a file I have it looks like 1 11063 upstream_gene_variant 1 13011 intron_variant&non_coding_transcript_variant 1 13259 ...
3
votes
5answers
78 views

How to remove lines which contain asterisk by using sed command

I have a file which contain following lines. **;**;**; *(Eng_Sen:This is an apple)*;*(WordID:1 2 3 4)*;*(message:)*; **;**;** I want to delete all the lines which contain following patterns using ...
1
vote
2answers
45 views

Remove everything before first occurence of specified word

How can I remove everything before the first occurence of a specified word using sed? What I have tried so far: echo $(cat /etc/nginx/sites-enabled/default | sed 's/^*.server/server/') > ...
2
votes
4answers
44 views

Trim beginning of a text file

I have a text file with unexpected spaces at the beginning and would like to trim the beginning and save it. How can I do it? I have tried a very simple example I have found on the internet but it ...
9
votes
1answer
422 views

Is there a way, ideally using the command line, to convert multiple .csv files to one multi-sheet .xls spreadsheet?

Is there a way, ideally using the command line, to convert multiple .csv files to one multi-sheet .xls spreadsheet? If there isn't a cli solution, it'd be good to know if there's an API that works ...
3
votes
2answers
85 views

How do I get a list of users not present in a CSV file from /etc/passwd?

I need to compare the user list (/etc/passwd) to a .csv file of account and get the account from /etc/passwd that are not in my csv file. /etc/passwd shows: root:x:0:0:root:/root:/bin/bash ...
2
votes
3answers
190 views

replace a string by variable in a file using bash script

through bash script, I am trying to find a value-number- from a text in a file, then make a new variable then replace it with a string in that file for example. in a file in /root/test.txt , i have a ...
-1
votes
3answers
56 views

Extract info from file

Is there an efficient way to parse a file like: 2 41620 . T G 100 PASS ...
1
vote
2answers
108 views

text between 2 words with some lines before patterns

how can I find lines between two words with 3 lines before START_WORD in sed or grep or ... for example output from a command is: my name is Mansour and I confuse to use sed or grep for piping my ...
0
votes
1answer
51 views

How do I write an output of one command into a file? [duplicate]

Let's say we got a content of the following command in bash, which consists of several rows, and just one column: tacmd listsystems | grep -i $i | awk '{print $1}' This content is a list of offline ...
4
votes
3answers
100 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' ...
0
votes
3answers
196 views

How can I count lines of differently named files, and write the outcome to a csv file?

I'm writing a script to analyse some data. I have several subset of files, and I would like to count the line from these files and write the result into a csv file. I'll try to do an example. I have ...
3
votes
2answers
58 views

Replace first column on a file

I have the following file. 101; John Bauer; 811-7780831; 102; Anthony Higgins; 844-4317627; 102; Anthony Higgins; 844-4317627; 103; Arnold Sipes; 866-4343123; 104; Donald Quinn; ...
8
votes
5answers
656 views

I need help with Grep to start at a section

I have some text files that I want to grep a section of code from. The goal I am trying to achieve is to start the view at a certain line & then be able to read anything below it. For example. In ...
0
votes
2answers
47 views

Find all occurrences of a word in a file and add a string to them?

I have a file containing my source code for a project I'm working on at the moment. I have the word resolution scattered over the file, and want to prefix it with self. --snippet-- resolution = ...