1
vote
3answers
75 views

How do I Copy and Paste lines between a start and end keyword?

I have two text files, and I want to copy a bunch of lines from one to the other. File one has a list of packages, and I want to copy it to list two. This list of packages isn't at the start of file ...
1
vote
2answers
26 views

Have grep output spaced for each file

When I do grep on a bunch of files, and several file have the word I am looking for, the output is hard to read as it's one after the other. Is there anyway to insert additional \n's after the ...
2
votes
3answers
41 views

bash - extract filenames from html file containing multiple links

I have downloaded an html file autogenerated by a script on a webpage. The file contains multiple links, including links to images I am trying to extract the full names of the images, for example ...
2
votes
2answers
53 views

tr complains of “Illegal byte sequence”

I'm brand new to UNIX and I am using Kirk McElhearn's "The Mac OS X Command Line" to teach myself some commands. I am attempting to use tr and grep so that I can search for text strings in a regular ...
5
votes
2answers
59 views

Grepping for a block of text with parts that can be optional

I have multiple entries that describes an event in a very large log file, say A.log. I would like to do two things with the event entries in the log file: Count the number of occurrences of each ...
6
votes
8answers
557 views

Grep rest of line…after match

I have a file containing only two lines, with the following structure: $ cat /tmp/pwpower.log 000D6F0000D34227, -114.10 000D6F0001A405C4, -130.09 The values are power values of my solar plant. ...
1
vote
4answers
85 views

Getting data under or above a line

This is my file: print energy 1 end Local net energy (PE 0) = 1.635393034217E+05 kJ/mol Global net ELEC energy = 1.635393034217E+05 kJ/mol print energy 2 end Local net energy (PE 0) = ...
6
votes
10answers
516 views

Copy only Specific text of a file to another

I have a file abc.txt the contents are <classpathentry kind="src" path="Sources"/> <classpathentry kind="con" path="WOFramework/ERExtensions"/> <classpathentry kind="con" ...
4
votes
3answers
142 views

conditional coloring in grep

I have a simple bash script. One line of my script matches a "pattern" with grep and colors the match grep -i --color=always -- "$1" I need to modify it, so that it only colors the match, if the ...
2
votes
4answers
121 views

Color matching but print other lines too [duplicate]

I have an alias: alias grep='grep --color=auto'. I wish to have some way to print not only matching row but all of them and just color matching patterns. I doubt is there an option to do that in the ...
0
votes
2answers
121 views

Compare first column in different files

I want to compare one file with other files in the same directory. file1.txt contains: move 34#123# get 11#278 put 33#29#567#23 file1.txt should compare with files 1.txt and 2.txt. 1.txt ...
3
votes
3answers
175 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
144 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
70 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
129 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
74 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
144 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
967 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
1k 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
598 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
302 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
193 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
1k 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
126 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
231 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
96 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
110 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
351 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
158 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
55 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
49 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
87 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
487 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
130 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
258 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
256 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
532 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
2k 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
184 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
277 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 ...
4
votes
6answers
5k 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
459 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
669 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
155 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
324 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
155 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
317 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
255 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
98 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 ...