3
votes
4answers
136 views

Rearrange text file by prepending data rows with header row

I have a file whose content looks like this: 2009 150 0 0 0 0000 75.316 0.0400390625 0.00007 0.00000 0.8980 76.216 0.0400390625 0.00007 1.00000 0.9046 77.217 0.0400390625 ...
3
votes
4answers
135 views

Identifying genes from a list of genes

I have a gene list file. Some thing like this SWT21 SSA1 NRP1 EFB1 TFC3 MDM10 I have another file which also contains the names of these genes in my list along with other ...
2
votes
1answer
61 views

make grep confirm all matches

I am writing a "unit test" for a bunch of .tex files and want to check for incorrect entity names, e.g. "Data Items" instead of "DataItems". Currently, I use grep to search for the incorrect ...
2
votes
5answers
90 views

identifying words in file 1 and matching them to second file and printing them

I have two files as follows File 1 has list of Ids ram Tarah taikah jhdfklj File 2 has id=ram;*between*hkjhdswklf kjsdklhglshglkhgklsdgkhdfg id=taikah;jhdjfkhg**kjdfkjksfdjk ...
0
votes
4answers
53 views

What are alternative tools for searching files in full content?

I realized that most of the text related tools I use, grep/egrep/awk/sed are line-oriented. I guess that is a simplified approach to search in files but I was wondering if there is another set of ...
5
votes
1answer
95 views

counting multiple patterns in a single pass with grep?

I've written a grep loop to iteratively count DNA trinucleotides within a gzipped DNA fasta file containing DNA sequences e.g. declare -a tri=(AAA AAC AAG AAT CAA .. etc) for i in ${tri[@]} do ...
16
votes
9answers
831 views

Grep lines but let the first line through [duplicate]

Consider the following output from df. Filesystem Size Used Avail Use% Mounted on /dev/sda1 23G 6.1G 16G 29% / udev 10M 0 10M 0% /dev tmpfs 397M 420K ...
1
vote
3answers
558 views

Count tabs per line in text file with utils

I have a tab-tabulated file. I would like to check if every line has the same number of tabs. For first step, I'd like to print the number of tabs for each individual line. I've tried grep -o '\t' ...
2
votes
6answers
221 views

Remove lines that do not start with a pattern from a given set of patterns

I have a file that contains data like this: report aaaaaaaa - .. -th bbbbbbbbb -to ccccccccc .. --. Question: I want to remove any line that does not start with following strings : report ...
1
vote
2answers
153 views

Show only part of the line found by grep (but not the part that matches the pattern)

In ifcfg-eth0, I managed to grep "DEVICE=eth0" by using grep "DEVICE=" ifcfg-eth0 But how can I grep pattern to show only "eth0"?
1
vote
1answer
164 views

How to use awk or sed to convert csv diffs into more readable format

Can anyone give me the example of how to use awk or sed (not sure which one, as I haven't use either of these much, as I have mostly been using grep and cut to work with csv data) to convert ...
12
votes
8answers
799 views

How to perform a multi line grep

How would you perform a grep for text that appears on two lines? For example: pbsnodes is a command I use that returns the utilization of a linux cluster root$ pbsnodes node1 state = free ...
1
vote
1answer
100 views

Retrieving two matches from repeated pattern

How can I retrieve matches from two repeated patterns: mappedname & its value in the text below?. MapName:abc someDiffName=someDiffValue x=3 y=6 NeedyMappedName=NeedyMappedValue . . Flag=true ...
6
votes
5answers
221 views

Get filesystem name and usage with `df -h`

df -h | grep test | sed -e 's/*%.^ //g;s/.*[ ^I]//' Output: /test /test/drv0 /test/drv1 df -h | grep test | cut -d '%' -f1 | sed -e 's/*%.^ //g;s/.*[ ^I]//' Output: 10 20 15 I want to ...
2
votes
2answers
79 views

selecting specific string in a field

I have this file: N104 F1810 N104 F3810 N104 F810 N104 F305 and a script to grep an input. Script: enter input read input cat file | grep $input when I input “810”, I get the ...
0
votes
2answers
97 views

Count lines with alphabet in linux

I have a file with a number of lines in a file filename. I want to count how many lines start with character 'a', with 'b' and so on in one go. What command i should execute.?
2
votes
3answers
234 views

How to grep the last number on a line in a bash script

I have output from the smartctl -a command; one of the lines looks like this: 9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 301 I've placed this into a variable (if that's the correct term) ...
4
votes
2answers
132 views

Printing lines from one file if part of them appears in another. Both files are millions of lines long

I have two files, let's call them 123.txt and 789.txt. 123.txt is 2.5M lines long, and 789.txt is 65M lines long. Is there any way to use grep or similar to keep any lines from 789.txt that contain ...
1
vote
1answer
49 views

How to use GNU tools to extract and merge two substrings of the same string?

Suppose I get the following result after doing a grep "emailed" /home/John/logs/2013-07-10.171222-0400EDT.html:I have emailed Mark. Thanks I want to extract the date from this so that my output ...
-1
votes
1answer
48 views

Is there a grep switch that reads a file for filter terms?

Assuming file a.txt has: 1a 2b 3c 4d so grep "1" a.txt would return: 1a and grep "3" a.txt would return: 3c what if i want to put a criteria file named crit.txt with the following ...
1
vote
2answers
78 views

Grep and sort several unsorted things in several lines (in one document)

I have a file with several unsorted things in one line which I want to put into a new file This is an example of part of the file I have: X1314448: SaMi|SM_g2554.t1 SaMi|SM_g5072.t1 Des|Des_g3808.t1 ...
4
votes
2answers
340 views

How to adjust column width in Linux command output

When I used this command on Red Hat Linux /usr/sbin/ss -i I get the following output below: State Recv-Q Send-Q Local Address:Port ...
3
votes
2answers
113 views

Can I make grep treat escaped multiline as a single line?

How can I make tools like grep treat multilines escaped with a backslash as a long single line? Let's say I have some files that looks like this: testvar=test1 \ test2 \ test3 ...
1
vote
2answers
236 views

How to count the number of words and print the lines that match exactly a given pattern?

I want to count the number of words and print the matched pattern lines which matches exactly with following pattern: abc-ERROR: The input File contains: # abc-ERROR: xyxxkkfgfr # def-Error: ...
2
votes
2answers
231 views

add “#” in begining to selected lines in File

Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B File A abcd abdc sdfg asdfa jon ram File B jon abcd grep file B from file A and add "#" ...
4
votes
4answers
438 views

Count lines matching pattern and matching previous line

I want to count the number of times that a role is successfully deleted. The problem is that one line of the log file will show that the script is about to delete the role: Prepare to remove role X ...
1
vote
4answers
1k views

Getting a list of users by grepping /etc/passwd

For a homework assignment, I need to use grep to parse /etc/passwd and get a list of all users (their usernames only, nothing else). It should use a pipe, and the results should end up in the allusers ...
2
votes
2answers
158 views

using grep to show entries that match a pattern and are present at least X times

I have a file that have entries like this among other lines Feb 16 17:30:18 ns1 dovecot: pop3-login: Disconnected (auth failed, 1 attempts in 17 secs): user=<accountin@myserver.com>, ...
3
votes
3answers
60 views

How to separate numerical values from identifiers

I'm currently writing a shell script that seperate values from their identifiers (retrieved from grep). For example, if I grep a certain file I will retrieve the following information: value1 = 1 ...
3
votes
2answers
221 views

sort a file based on length of the column/row

I need to sort a file based on the number of chars in the first column. I have no idea on how to go about this. (On Linux, so sed/awk/sort is available). An example: .abs is bla bla 12 .abc is bla ...
2
votes
5answers
3k views

How to print all lines after a match up to the end of the file?

Input file1 is: dog 123 4335 cat 13123 23424 deer 2131 213132 bear 2313 21313 I give the match the pattern from in other file ( like dog 123 4335 from file2). I match the pattern of the line ...
2
votes
3answers
385 views

Extract integers enclosed in round brackets

I'm new to Linux. I've a file which contains list of movie names and their release year. I want to list out all release years. Specifically my file looks like below TDKR(2012) Vicky Cristina ...
4
votes
3answers
533 views

Delete the matching line and several more from a file

I have a text file called file_a.txt. My first command is grep -A 12 ".production =" file_a.txt The output is a few block. Each block of string contains 13 rows I specifically want to delete all ...
2
votes
2answers
136 views

How can I enhance the output of find and grep?

I really don't look forward to having to do find/grep because the output, as returned by find . -exec grep sometext {} \; -print is just not very easy to read even when you dump it in a file. What ...
3
votes
4answers
306 views

Grep one liner to remove blocks of random text

Using a script to backup some Cisco routers and compare startup and running configs. My output is tarnished by some ssl certificates it returns - I wish to remove them. Given: ********* ERROR ...
3
votes
1answer
139 views

grep for n or more periods on a given line

I want to be able to arbitrarily match lines that contain a lot of periods, like this: $ echo "there's. someone on the wing. some. thing." | grep -stuFF [[:idunno:]]{4,} there's. someone on the wing. ...
3
votes
3answers
287 views

Display lines inbetween text with grep

I know that I can use the -A and -B command for grep to get a lot of what I am looking for however that is not quite what I want. I am looking to parse the httpd.conf file to search for a domain. ...
3
votes
1answer
239 views

grep list of names and information from bigger file

I have two files: one with list of names (500 entries) and other having some more information for each entry in A.txt and extra entries too. File A.txt (each line is starting with > (fasta format) ...
2
votes
2answers
95 views

reformat a text file to have all text on one line using CentOS 5.6

I have a 210-line block of HTML that I have stored in a HTML for debugging purposes. The HTML, as you would expect, is formatted accordingly so is stored in the file with spaces and tabs. Is it ...
3
votes
1answer
2k views

Delete last character in a word but only if the character is there - in bash

How to remove last character only if it's there? input: OpenOffice.org/m openOffice.org/ozm Pers. Pfg. phil. Prof. resp. Roonstr./m roonstr./ozm desired output: OpenOffice.org openOffice.org ...
2
votes
1answer
453 views

How can I use unix tools with Cyrillic text?

I recently started processing Cyrillic text, and it's been really difficult. I couldn't get my Python scripts to work with it at all. And I tried. PHP worked well, but I don't know PHP. I just ...
2
votes
2answers
1k views

How to do a regex search in a UTF-16LE file while in a UTF-8 locale?

EDIT: Due to a comment Warren Young made, it made me realize that I was not clear on one quite relevant point. My search string is already in UTF-16LE order (not in Unicode Codepoint order, which is ...
5
votes
1answer
386 views

inexact text search

Is there any utility like grep or even uniq but for inexact search or I should write it myself? I mean it will look at 90% (number may vary) matching, or smth like that. For example I have file with ...
3
votes
3answers
615 views

Longest common substring using grep

I have a huge text file called dictionary.txt with entries like ABC_SEQ_NUM This represents.... ABC_RANK This represents.... ABC_BSC_ID This represents... PQR_TA_DATE_AF This ...
2
votes
2answers
3k views

Grep: search and replace full line

The command grep "foo" myfile.txt prints all matching lines in my file. Now I want to replace the full line with another string. How can I do that?
4
votes
2answers
3k views

What is the python equivalent of grep -v?

I like grep -v. I use it all the time. But I am also doing some text processing in python, and there is one crucial thing that I lack. Usually, I use grep -v to take extraneous stuff out of text. ...
1
vote
3answers
297 views

grep equivalent of the kwrite regex [A-Z][A-Z]+

So, it took me ages, but I finally learned to think in terms of regular expressions, thanks to using them in kwrite. But I still don't know how to translate that knowledge to grep. I love my grep, ...
6
votes
1answer
396 views

How to detect and delete lines containing ˆ@

I have a simple problem: In my file, the are lines containing the string ˆ@ˆ@ˆ@ˆ@ˆ@ˆ@. I just want to delete all lines with this string, using for example the sed or grep commands. And I would like ...
3
votes
3answers
3k views

How to search and replace text in all php-files in a directory and it's subdirectories

I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern. The search pattern is quite long ( > 5000 ...
3
votes
5answers
250 views

evaluate multiple patterns from program output and write into pattern specific files

I have a script outputting some value/numbers and I want to split those into two files. I am looking at something like: ./runme.sh | grep 'ook' >> ook.out | grep 'eek' >> eek.out Where ...