grep is a command-line utility that is used for searching text.

learn more… | top users | synonyms

1
vote
2answers
116 views

How to grep for groups of n digits, but no more than n?

I'm learning Linux, and I have a challenge that I seem to fail to solve on my own. Here it is: grep a line from a file which contains 4 numbers in a row but not more than 4. I'm not sure how to ...
0
votes
2answers
38 views

Copy a word from the html file of a web page using shell script

I am trying to write a shell script which should crawl into a web page and fetch a particular character/phrase from its html and display it. Particular character means, for example if the html of the ...
-2
votes
0answers
39 views

using grep or any of its variations [closed]

Write a regular expression to match proper date. Date has the following format dd-mm-yyyy, where dd is in the range of 01 to 31, mm is in the range of 01 to 12, and yyyy is in the range of 1900 and ...
-5
votes
1answer
39 views

using grep or any of its variations

Write a regular expression to match a proper IP address. IP address has this format: x.x.x.x , where x is any number in the range of 0 to 255. e.g. 192.168.0.1 10.100.0.3
3
votes
1answer
69 views

Find a file which contains a string and delete it in Ubuntu

My CMS is full of SPAM scripts and they are almost in every folder. I figured out, that I can find those scripts by using this find/grep command: sudo find . -type f \( -name '*.php' -or -name ...
1
vote
1answer
91 views

What environment does xargs pass to grep?

I am trying to search for two strings in a file. This is the command that I am using grep -l -r ads2gas | xargs grep vp8 For some reasdon the second grep is not working correctly. I am getting "no ...
0
votes
2answers
14 views

Grep searching for words by letter

I'm searching through a file of people that is structured like below John Smith 555-555-5555 Harvard Square, Boston I'm interested in finding all the LAST names that start with the a certain ...
0
votes
2answers
21 views

Grep printing a line that doesn't contain a set of numbers

I'm trying to get Grep to print all lines in a txt file that do not contain the numbers 834. When I try "grep [^834] file.txt" it still prints all the lines containing 834 but just doesn't highlight ...
-2
votes
3answers
61 views

How to grep keywords with unique value? [closed]

I just want data those have unique value, say we write log file for mobile users <mobile_number1>|20141006 06:15:26||AKQY6LYACZAA4O|12|3|BIHAR| <mobile_number2>|20141006 ...
0
votes
3answers
35 views

What's the easiest way to list files of a given extension, save that list to a text file, but omitting the actual extensions when in the text file?

This is for a counterstrike server, where mapcycle.txt contains all the maps found in the maps/ folder, but the list of maps must not contain the .bsp extension. Example of maps/ folder: map1.bsp ...
0
votes
1answer
16 views

Explain in details egrep line

Hi i found in the internet egrep line. The line founds the longest line in the text. But i dont understand specific elements. Maybe someone could explain me all line? Here it is: egrep -n "^.{$(wc -L ...
2
votes
6answers
869 views

How to command grep not to display the searched string? [duplicate]

I want to print a part of a line in a file. The whole line looks like this. Path=fy2tbaj8.default-1404984419419 I want to print only the characters after Path=. I have tried grep Path filename | ...
1
vote
0answers
18 views

How to get previously install package information?

Is there a way using dpkg, apt, logs, or any thing else, where I can query/retrieve previously installed versions of an application? I don't care about which previous versions were available up to the ...
2
votes
1answer
86 views

'grep' command not working on Lubuntu

I'm using Lubuntu 14.04 with a fresh install (Monday) and I noticed that my grep command doesn't work. Whatever I do, it shows me the grep usage page. For instance, if I try to run: grep test * or ...
0
votes
1answer
322 views

Return only line number, if pattern 'Exist' and 'Not Exist'. using 'grep' command

I have this sample file for my input: xyxxyx xyxx xxyx yxyy yxyx xxyxxx xx xyx xxx x y x xxyy yxxy xyxxy xxy y x y xyxy xyx yyxx xyyxyxy xyx yxyy xyy yxyx xxyxyyx And I tried to find only "xyx" ...
2
votes
2answers
135 views

append a word to the end of a line in txt file

I have a file that should have "OK" at the end of a certain line the line that should be modified is the first line not ending with "OK" I can grep the file to get the line to be modified using ...
0
votes
0answers
13 views

How do I djvubind on ls and grep result?

How do I djvubind only files that are in ls | grep -P "page\\d\\d\\d.tif"?
4
votes
3answers
286 views

Searching for patterns in csv files

I have file.csv that looks like this 4,6,18,23,26 5,12,19,29,31 2,5,13,16,30 9,10,24,27,32 4,5,10,19,22 4,6,8,10,25 2,3,4,25,11 I want to find some patterns and save them in another log file ...
0
votes
1answer
76 views

Linux : Data extraction from text file

I have a text file in which thousands of data is there. eg. id=row_value profile=row_value name=row_value email=row_value address=row_value id=row_value2 profile=row_value2 name=row_value2 ...
19
votes
3answers
589 views

Saving output of a grep into a file with colors

I need to save the result of a grep command into a file, but I also want the output file to be formatted and keep the colors just like in the terminal. Is there a way to do that? Maybe make grep save ...
4
votes
5answers
194 views

Bash script programming: how to match pattern in string?

How I can get this whole value 7I45432ZX from below lines: PW*3434*453*256*PE*UB PO*00*NE*7I4543 2ZX**20140617 PW*3434*453*256*PE*UB PO*00*NE*7I4543 2ZX**20140617 This is the code I tried: grep ...
2
votes
3answers
78 views

How to use grep to search for a pattern which starts with a hyphen (-)?

sudo find / -name "*" | xargs grep -sn --color=auto "-j" Above command returns below: grep: invalid option -- 'j' Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information. ...
0
votes
1answer
46 views

Check user input is alpha numeric

Hi Im not any sort of programmer but found myself creating an install script which installs mySQL which works fine. I would like to improve the script by asking the user to enter text that will be ...
-1
votes
1answer
48 views

list directory name of symbolic link

I am trying to find all the symbolic links on my system with name keytool. I use the below command : ls -lR | grep keytool It gives some results, but i want the directory names as well. So i use ...
2
votes
0answers
92 views

Why can't I redirect grep output to file? [closed]

I am running command like this. # ( ( partclone.restore -X -s some.img -o /dev/sda3 2>&3 ) 3>&1 ) | grep Completed Completed: 0.40% Completed: 1.23% Completed: 2.07% ... ...
0
votes
1answer
45 views

Search for files contain lines with many conditions

I can search for files which have a specific word by using grep grep -l "word" /path However what if I want to search for files which have "word 1" and "word 2" in a same line? I can use: mkdir ...
0
votes
1answer
48 views

How to filter grep results?

I am new at writing scripts. So I am hoping this is simple. The script I am writing is used to gather system information and save it as an html file. When I run: sudo lshw -short it list all of ...
3
votes
4answers
1k views

Redirect an output to a file from command piping grep

I am running this: cat /dev/urandom|hexdump| grep -i "ffff f" > random and I get nothing in file random, it remains zero length after the command is interrupted. How to make it writing output ...
0
votes
0answers
32 views

Issues with Grep [on hold]

Why does the bottom line output "0" into the "AD-Results-$month-$Y" file? First grep command fgrep "$month $D $i:" $Filetmp > TempOutput Grep command to read "allows" from tail of ...
0
votes
3answers
44 views

Filter only path of files (without directories path) from output using pipe |

rpm -qpl dhad-9.0.27891-2.x86_64.rpm allows to display all file paths and directory paths of this package . Example of output : /opt/dhad/tv_bin/wine/lib/wine/winmm.dll.so ...
0
votes
1answer
57 views

Can someone explain what this grep/cut/awk command is doing

This is inside of a .sh script file: cd /somefolder IP=$(ifconfig | grep 'inet addr:'| grep 168 | grep 192|cut -d: -f2 | awk '{print $1}') The /somefolder has another folder list with a single ...
1
vote
2answers
117 views

Grep, no value return

I am searching for a word, in this case "hehe" that is located in the file findTest by using grep, but when i initiate the search: grep -r "hehe" or grep -lr "hehe" it starts but after 5 min ...
1
vote
3answers
39 views

Document Sorting Section

I have some sample data below (call it test.txt). I would like to split this big document into 3 documents by searching the first two digits in the 4th column. I'm pretty new with Linux (Lubuntu ...
0
votes
0answers
210 views

Cannot run the terminal: “Not such file or directory” and “hostname has changed”

My problem is: I can't use the terminal in Xubuntu 14.04. If I launch it, this error is appearing: grep: /opt/aster113/etc/codeaster/asrun: No such file or directory Hostname has changed, running ...
1
vote
1answer
37 views

Changing current directory to directory that have identifier as the substring

My terminal is currently in the home directory, and the home directory contains a directory which have "round" as the substring. Is there any way to directly change to that directory without typing ...
1
vote
1answer
62 views

Parse git log by modified files

I have been told to make git messages for each modified file all one line so I can use grep to find all changes to that file. For instance: $git commit -a modified: path/to/file.cpp/.h - 1) ...
2
votes
1answer
89 views

How to grep the output of youtube-dl?

The normal output for youtube-dl is the following [download] Downloading video #3 of 33 [youtube] WbWb0u8bJrU: Downloading webpage [youtube] WbWb0u8bJrU: Downloading video info webpage [youtube] ...
0
votes
3answers
145 views

Get intersection between two files using command line

What is the most efficient way to get the intersection between two files , there is : sort file1 file2 | uniq -d
4
votes
1answer
260 views

How can i watch the output that was filtered with grep?

I want to watch the changes of the output gsettings list-recursively|grep text-scal which is org.gnome.desktop.interface text-scaling-factor 1.0 com.canonical.Unity.Interface ...
1
vote
1answer
114 views

Keeping color from vim with grep

I like the way vim highlights the output from syslog. However, I only want the most recent outputs to be opened. I tried grep --color=always "$@" /var/log/syslog > /tmp/fileOUT vim /tmp/fileOUT ...
0
votes
2answers
208 views

Find specific word in all files in and beneath current directory

I want to find all files, and print the path and filename, for any file where the text "Numlock" is used - whether it is lower-, upper- or mixed-case. What command should I use ?
1
vote
1answer
99 views

How can I extract pages containing a given string from a PDF file?

I have a PDF file containing 100 pages. I would like to extract those pages containing a particular string. How can I achieve this? Maybe by using ghostscript on the command line? For what it's ...
4
votes
2answers
603 views

Filter terminal command to text file

Problem: I have dmesg | grep ttyUSB command that has the following output: [ 7.648896] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB0 [ 7.649091] usb 1-2: GSM modem (1-port) ...
1
vote
1answer
390 views

Difference between 'grep' in Ubuntu and Kali Linux?

I always used the following command to filter out my contacts email addresses from a directory in Kali Linux: grep -rIhEo "\b[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+\b" >> 1A I tried ...
4
votes
2answers
767 views

regex search works with `grep -E` but not with bash script?

I use the same regex with grep and it gives me a match but when doing it in a bash script, it return no match. Test String(part of the file testregex.txt): <a ...
1
vote
1answer
131 views

Searching for file contents on whole disk

I am trying to find my old IP address in config files in order to replace it by my new IP address. I found one answer that proposes the command sudo grep -HrnF '1.2.3.4' / to find those IP ...
2
votes
3answers
119 views

Search and print the lines from the output which can contain lines with errors

I have a command example, device list which gives me all devices with their status as okay or error in the following format [okay ]: you are listening on : 11 [error ]: not currently ...
1
vote
2answers
87 views

how to trim dpkg upgraded packages list

Latest upgrade borked my system and I`m trying to revert the last upgrade. I opened my comp with live USB and chrooted to partition that is OS installed. I get the upgraded packages with cat ...
0
votes
1answer
51 views

grep keeps printing the same string

I typed grep ch->spl[4] * into my shell to look for something in a mud code and its broken grep now. Any time I try to grep anything pretty much it puts the spl[4] before the filename like this. ...
2
votes
3answers
3k views

Using grep to search texts with single quote?

I am using gedit text editor with embedded terminal in ubuntu 12.04. I'm trying to search for some text using grep. I want to search for this line of code 'type' => 'select' I tried: grep -r ...