Tagged Questions

grep is a command-line tool for searching text patterns in files

learn more… | top users | synonyms

0
votes
1answer
44 views

No output from grep -P 'com\K\w+'

I have a source file saved off the internet which has various links I want to pull data from. For example https://blahblah.com/uniquetext I'm using grep -oP 'com\K\w+' source.txt > list.txt ...
1
vote
2answers
77 views

grep pattern exacly matching from file and search only in first column

I have a bigfile like this: denovo1 xxx yyyy oggugu ddddd denovo11 ggg hhhh bbbb gggg denovo22 hhhh yyyy kkkk iiii denovo2 yyyyy rrrr fffff jjjj denovo33 hhh yyy eeeee fffff then my pattern file ...
1
vote
2answers
116 views

How to grep for something that's in an environment variable and has a forward slash?

I want to grep a file, and I want to get all the lines that have a certain environment variable (to be exact, $PWD). Of course, using just cat file | grep '/'$PWD'/' is not working, since $PWD ...
0
votes
2answers
33 views

Read file and find all occurances and generate hash for the content in between the occurance

I have a file like this : 1 Record|1111|ABC 2 text in between for record 1 3 text in between for record 1 4 Record|2222|XYZ 5 text in between for record 2 6 Record|3333|XYZ 7 text ...
5
votes
2answers
121 views

Suppress 'file truncated' messages when using tail

I'm tailing a log file using tail -f messages.log and this is part of the output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget tellus sit amet odio porttitor rhoncus. Donec ...
2
votes
1answer
55 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 ...
1
vote
2answers
20 views

Zero input_file_names in Grep

From the manual for grep, the general form of grep usage is: grep options pattern input_file_names In particular, it is stated "There can be zero or more input file names." What files are ...
2
votes
7answers
216 views

Formatting the output of grep when matching on multiple files

When searching on multiple files, the output of grep looks something like this: {FILE}:{MATCH} This is a problem since if I double-click on the {FILE} portion, I will at least also select (and ...
0
votes
1answer
22 views

How do I add text to an output file?

I have a script for doing whois lookups: #!/bin/bash for domain in `cat /Users/jason/Desktop/letters.txt `; do echo $domain >> /Users/jason/Desktop/whois-results.txt whois $domain | grep ...
1
vote
0answers
24 views

Review GREP and FIND results in Xemacs

I spend a lot of time searching code. I really like grep and find, because of all the options available. But it takes way too long to navigate the results. I use xemacs and it takes 3 more commands ...
0
votes
2answers
26 views

Grep matching cell of the csv file and index of that row

I have csv file and I want to see numbers that start with 0.99 and their row's index which is the first cell of that row. This is what I have so far: cat fil.csv | grep '0\\.99'| tee > (cut -d, ...
3
votes
3answers
124 views

Grep for searching pattern in a file

I want to use grep to search pattern from one file in a second one. My pattern file is something like: K02217 K07448 KO8980 The file to search in is: >aai:AARI_24510 proP; proline/betaine ...
6
votes
1answer
132 views

Conditional grep without quiet option

I always thought the quiet (-q) option had to be used when using grep conditionally. But re-reading the man page it seems like it should work without it. So if you want to print matches and use it in ...
0
votes
2answers
64 views

Unix grep confusion

I am doing an assignment for school and using putty to complete the assignment. The format of the assignment does not allow for much variation and thus only one answer is sufficient enough to allow me ...
1
vote
2answers
56 views

Seaching a File in Unix for a given string and then another set of Strings within this file and print file properties too

I am using command to search for files staring from a given Directory in Unix , files ending *.sas and containing the string DB2. I then inturn want to search the resultant set of files for the ...
2
votes
1answer
41 views

Help with using quotes in grep searches

I have a file with variables in it of the form a(i)%b(j)%c where the a, b, and c are always the same, but the indices i and j may be different (including multiple characters). So I've played around ...
1
vote
3answers
88 views

Print total free memory from `free -m`

free -m currently puts out something like this. I would like to know using grep/awk how we can get the total free amount. i.e. 9083
0
votes
3answers
75 views

Simple way to extract value from HTML

I have a very simple html file with a value inside. Value is 57 in this case. <eta version="1.0"><value uri="/user/var/48/10391/0/0/12528" strValue="57" unit="%" decPlaces="0" ...
2
votes
1answer
21 views

egrep multiple patterns with dashes

I am trying to match the followings with egrep '201411[08|09|10|11]-[117|111]-' 20141108-111-xyz-abc 20141110-117-342-lala But for some reasons, the 2nd character class pattern ([117|111]) doesn't ...
1
vote
2answers
87 views

Search 2nd line of files and print filenames to stdout

I have a few directories of ~10,000 files. What's the quickest way to search each file and return the filename if the second line contains a specific string? Edited for clarity
1
vote
2answers
41 views

find field pattern in a csv file then count unique field values

I am using Cygwin (bash) to create a script to find, group and count fields in multiple CSV files. Each row will have comma-separated fields with each field following a similar convention. There is a ...
3
votes
3answers
195 views

How can I delete all text between curly brackets in a multiline text file?

Example: This is { the multiline text file } that wants { to be changed } anyway. Should become: This is that wants anyway. I have found some similar threads in the forum, but they don't seem ...
-1
votes
1answer
43 views

Information about grep cammand [closed]

Both two outputs came in my terminal. sda 13.45 479.55 84.92 812139 143808 sda 5.00 4.90 4.00 13 24 I want to get ...
3
votes
1answer
60 views

How to format grep results?

Wow, I could not think of a good way to title this question. Basically I have a file called "attendance" with data like this: 11/06/2014 101.11.001.01 FirstName LastName 11/06/2014 101.11.001.01 ...
1
vote
5answers
64 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
2
votes
6answers
88 views

Getting the matched word exactly

I have looked through a number of question but they do not satisfactorily reply to my question. I need to print words that match the pattern exactly not the lines containing that word. For example: ...
4
votes
0answers
91 views

what is grep -v -f /dev/null expected to do exactly?

Theory: grep -f somefile or grep --file=somefile will find all lines that match one of the patterns listed in somefile. If somefile is empty, nothing will match. With grep -v you list lines that do ...
2
votes
1answer
65 views

grep of a shell variable finds nothing

I have some problem with grep. I wrote a script which need to find some numbers from a list (file name ContigsNames) in a database. I wrote the following script: file=ContigsNames while IFS=' ' read ...
2
votes
3answers
48 views

Removing lines from one file based on non-existence in another

I need to remove lines from fileA which has two columns if fileB (one column only) does not contain the string from column1 in fileA. Any linux command would help. Thanks. Example. Here is fileA: a ...
0
votes
1answer
13 views

add fields from different lines in one line

I'm trying to add the .data and .bss sections of the size -A output size -A mylib.so | grep "\.data" | awk '{print $2} this will print the value of the size of the .data section. I guess I could ...
0
votes
3answers
76 views

How do I search a file for a string then use it as a variable?

I have an XML file that looks like this: <id>456</id> <root> <value>1</value> <intNum>2</intNum> </root> <root> <eulav>1</eulav> ...
3
votes
3answers
67 views

How can I base the file name off of an already existing variable?

I'm using this to delete lines that don't match a pattern: $ egrep "pattern1|pattern2|pattern3|pattern4|pattern5" But now I need to do it automatically, so I'm setting a variable like this: $ ...
0
votes
2answers
32 views

Delete consecutive lines if patterns match in each line

Good day, I was wondering how to delete to consecutive lines when this pattern is found: /^pt [a-z]\npy [0-9][0-9][0-9][0-9]\n// Expected Input pt a py 01234 pt b cd abc py 5678 Expected Output ...
2
votes
1answer
48 views

how to use grep -v in an expect script

I'm new to expect scripting, trying to implement below command (that works otherwise) in an expect script $ grep -i cps config.cfg | grep -v "//cps" | grep -v "cps := 4.1" | \ grep -v "cps := ...
0
votes
0answers
40 views

How to prevent grep from excessive unnecessary memory usage

I'm greping a hexadecimal pattern (currently a number) from a large binary file (1 TB) with xxd -p /path/to/sda.img | tr -d '\n' | grep -ob '117a0cb17ada1002' and I'm wondering why grep uses up to ...
2
votes
1answer
38 views

Extend grep to find a match after the first match

I have a long list of strings separated by newlines and each section separated by a string starting with ~ (there are no other ~ in the file). I want to extend grep to find the ~ text right below the ...
0
votes
1answer
62 views

Grep -m 1 doesn't work

I'm using the following command to parse a form element from HTML using grep. The $RESP variable contains the output from a previous curl request ... echo $RESP | grep -m 1 -o -E 'name="id" ...
1
vote
3answers
65 views

How to sort the filenames shown in grep command based on timestamp?

In the following command, how can I get the file names based on its timestamp $ grep "exit 0" a* a1.txt:+ exit 0 a2.txt:+ exit 0 a3.txt:+ exit 0 a4.txt:+ exit 0 a5.txt:+ exit 0 $ ls -latr ...
1
vote
2answers
89 views

double grep on tail -f gives no output

If I follow a file somehow like this: tail -f /var/log/syslog|grep s I see all lines containing an "s" Why does this not give any output, if I grep it again to the same "s"? tail -f ...
1
vote
4answers
37 views

How to do grep even if the file is not present?

I am doing something like this in my code file_nm=`ls -latr *abc*` if [ `grep "search_txt" "$file_nm" | wc -l` -gt 0 ] then echo "string found" else echo "string not found" fi If the file_nm is ...
1
vote
1answer
66 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
-1
votes
3answers
60 views

Find files less than 1 week old with match TODO in files

My unsuccessful proposal find ./ -newerct '1 week ago' -print | grep TODO No output although should be. Files are text files like Lorem % TODO check this out Lorem ipsun How can you find less ...
0
votes
1answer
75 views

grep: input file 'X' is also the output

I use ubuntu 14.4, and attempt to redirect the output of grep command to a file, but I keep getting this error: grep: input file 'X' is also the output I've searched for this issue and just found ...
1
vote
1answer
39 views

tcpdump won't capture entire packet

I'm using sudo tcpdump -A -s0 -ien0 port 80 | grep schemas-microsoft >> ~/Downloads/convert.txt to capture microsoft-schema xmls being sent throught the internet, when tcpdump is supposed to ...
0
votes
1answer
29 views

Manipulate lynx --dump output to get only specific sections

I'm trying to write a unit that will get me a word's definition from wordnik.com from CLI. Currently my code is: function wordnik { (( $+commands[lynx] )) || return 1 ...
2
votes
3answers
158 views

Using grep/awk/sed to sort and combine 2 files

Ok I am running into a problem. I am taking a wifi log that has MAC addresses listed in it. I want to find out what MAC vendors/manufactors for the devices that are connected to my router. I have 2 ...
2
votes
2answers
249 views

How can I grep a certain text and display its line and the line after as well

I have a file similar to: abcdef 123 ghiflk 234 sfhskdhf 483 I would like to search for a string, and the output should include the next (and/or previous) line as well. So for example: grep "bcd" ...
3
votes
1answer
104 views

What is the purpose of those special characters in the sed command?

I found this bash command that creates a directory tree in your console window. I find it quite useful, but I don't really understand how all of the special characters work. Could someone help break ...
2
votes
4answers
62 views

How do i Reverse output already piped from sort and cut commands

I have to take user input of there UID then use it to reference the /etc/passwd directory and sort the data by first name and display only username,firstname,lastname in that order. The problem i'm ...
1
vote
1answer
44 views

Linux log file structure change for usage with kst

My file (tcp dump from networked sensors) has this shape: 20:06:57.049686 IP (tos 0x0, ttl 64, id 26871, offset 0, flags [DF], proto UDP (17), length 68) e108-193.eduroam.tugraz.ac.at.34225 > ...