Questions tagged [grep]

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

210 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0
votes
1answer
84 views

move file based on iso8601 date format that is 1 week old

I have a set of backups that run on a cron job every 4 hours (00:00, 04:00...etc). These files are named based on; NOW=$(date +%F-%a-%H.%M)-filename which translates to 2016-10-25-Tue-04.00-filename. ...
0
votes
2answers
716 views

Grep nload command

Hello I am trying to use grep alongisde with nload command to just get the current transfer speed: nload | grep Curr: But if I try this command I got only empty output and I have to quit with ...
0
votes
1answer
659 views

grep alias to safely ignore multiple directories

The day to day usage is: grep -rIn pattern directory There are some files that I want to avoid, they are in directories that have this kind of path in them at some point: app/lib/bower/lodash, app/...
0
votes
2answers
337 views

Replacing a given text in multiple files

I have a C project with many headers and source files. In these files I have a comment line for version of the program. Something like: /** * all the file info and stuff.... * VER: 0.01 * rest of ...
0
votes
1answer
209 views

search string using grep or sed from two files

I have two text files. Using sed or grep, how can i find matching string and then replace the string from text2.txt? It should search anything under name=" ". If found, replace it what is under path="...
0
votes
1answer
1k views

how to grep a tag value in xml file and print another two tag values in same xml file

I want to grep tag value of and if its 01 it must print another tag and along with its value . Sample XML file : <CustName>Unix</CustName> <CustomerId>999</CustomerId> &...
0
votes
2answers
431 views

Extracting all columns containing a list of terms

I have a data file (data.txt) with ~320 rows and ~1800 columns (1.9 MB), and I need to extract certain columns out (for all rows). The general layout of data.txt is as follows: ID ...
0
votes
1answer
236 views

Move files only if filename based regex does not match file in target dir

Best explained by an example: Source dir: file-a-1.txt file-b-1.txt Target dir: file-a-2.txt Expected result: file-a-2.txt file-b-1.txt Move all files from src dir to target dir only if file ...
0
votes
1answer
76 views

exiv2 piped to grep - random inconsistent behavior

For a bunch of jpg photos, I have this (simplified) script to be able to extract the original date when the photo was taken (if different of 0000:00:00, not relevant for this case) for f in *.jpg; do ...
0
votes
1answer
407 views

how to print the count of matched /unmatched patterns and print multiple patterns separated by line

how to print the count of matched /unmatched patterns and print multiple patterns separated by line. Input example (test.log): This 23 line has eight 8888 This 11 line has three 3333 need 12 to ...
0
votes
2answers
598 views

Select rows based on the values of a specific column (not the first column)

I would like to read a file.csv file and keep the rows (i.e., all the columns) of the file if and only if the sixth column of that file matches values in user_ids_to_keep.csv. The file.csv file I ...
0
votes
2answers
319 views

Problem with grep -o

I have a text file as shown below. 192.168.10.1 192.168.45.45 192.168.255.255 192.168.0.5 Random text comes here 8.8.8.8 224.23.25.12 225.1.2.3 226.0.0.0 227.1.2....
0
votes
1answer
104 views

What does a “*” at the start of a regular expression do?

In this case discussed: find (GNU findutils) 4.5.11 grep (GNU grep) 2.20 Let's say I have a directory that contains a bunch of files. I want to find the files named jtobdops02.key and jtobdops.02.cer....
0
votes
2answers
68 views

insert complex line before or after complex line

i have file with complex text print("ERROR: passwords don't match") password = hash_func(password.encode("UTF-8")).hexdigest() i need to insert this text between them with open('/etc/openvpn/...
0
votes
1answer
500 views

Standard deviation of number next to a pattern

I have a file with lots of tags with a number next to them, set out like this: <Score>4 ... other data <Score>2 ... other data <Score>3 and so on... I have used grep to get the ...
0
votes
1answer
65 views

Unix scripting : Writing to another file with “:” is failing

I have below record (and many other such records) in one file 9460 xyz abc (lmn):1027739543798. Taxpayer's identification number (INN): 123. For all IIB. 2016/02/03 I need to search ...
0
votes
1answer
678 views

live tail (tail -f) of file being grepped

i can do tail -f -n20 <file> to see the last 20 lines of the file, live. If i want to grep something, tail -f <file> | grep <pattern>, it will still be live, but will only grep ...
0
votes
1answer
1k views

Fetching logs from log file using grep

I am trying to fetch logs from log file using grep command and format of log file is as follows: [1/10/16 23:55:33:018 PST] 00000057 ServerObj E SECJ0373E: Exception message at com.own.ws.wim.util....
0
votes
2answers
67 views

finding how many options ls have

Just for practise i want to find out how many options does ls command have. I have written following piece of code man ls | grep -o -i '\-[a-z0-9]$' Why does this piece of code only printed -C and -...
0
votes
0answers
166 views

Finding word with centain length containing characters from interval

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following grep '\<[a-s]\{3\}\>' file.txt which outputs nothing , i have ...
0
votes
1answer
99 views

How to recover a node/content from a tarfile that's been overwritten

Disclaimer: I'm not very good at writing questions, and mine is a very specific scenario. So I'm just going to jump straight into the situation: I was browsing my filesystem, and somehow managed to ...
0
votes
0answers
705 views

Unable to match multiple ip addresses using grep

I am trying to match multiple ip addresses, 100.x..x.x and 13.19.x.x here is my syntax. for item in `cat s3` do egrep -o '100\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} | 13\.19\.[0-9]\{1,3\}\.[0-9]\{...
0
votes
1answer
1k views

Fetch second and fourth column from a file

Problem Statement I am not able to get the values in second and fourth column. Tried grep -i "AUGC\|AACN\|AACY" output.csv | cut -d ',' 2,4 DATA success,1234,["madhu",{'first',[{'last',18}]},"I0",...
0
votes
1answer
56 views

Print concat vars inside loop

I have a code like this: cat input | while read p; do lynx -dump "www.xyz.com/p?=$p" | grep -m 1 -A 1 "Hello" | awk -F: '{print $2}' >> output done Where the content looks like this: [$p ...
0
votes
1answer
2k views

Grep /var/log/maillog for email to a certain user, based only on his linux username

I have a learning environment, based on Linux CentOS, with Postfix and SquirrelMail running, but my assignment is more in general. I need to find in the maillog e-mails received by a certain user ...
0
votes
1answer
158 views

Grep unix for a data to find out result

i have a file, contains huge data. for example there is written "COST-> 1.00" line. and i would like to grep for example between 1.00 and 100. it includes both integer and string characters. how ...
0
votes
3answers
70 views

parsing out duplicate barcodes in a separate line

I've got the following data I need to parse out the duplicates from column1 into a separate file, For example, 21288003132541:cr 21288003267289:fr 21288003758683:ph 21288003758683:tag 21288003758683:...
0
votes
1answer
273 views

Delete email addresses in .csv that are listed in a .txt file

I run the following command to keep email addresses listed in emails.txt grep -wFf emails.txt file.csv > newfile.csv But how would I change this command to remove addresses from file.csv that are ...
0
votes
1answer
241 views

Script for update

I have a script used for update : OLD="int 10" NEW="int 20" i=0 DPATH="/home" for f in $DPATH do sed -i "s/$OLD/$NEW/g" $f let i++ echo "modified:" $f done what i need according to my old ...
0
votes
1answer
88 views

Search and replacing strings in a numerical data file

I have a data file I need to edit it is in the form: -8.915602898150751e-05-7.050591991128022e-05-4.361255125222242e-052.309505585477205e-05-2.223040239244275e-051.088544645124330e-011....
0
votes
0answers
61 views

Why does not changing changing LC_ALL from utf to C speed up my grep?

I wanted to try to speed up my already fast grep. I read that changing lc_all from utf to c was supposed to do this. However, it gives no speedup. What might the reasons be? How do I "debug" this? ...
0
votes
1answer
965 views

Search a file for a string in multiple directories

Can someone please help me with a command to search a file for a string in multiple directories? I am searching for the VIP in httpd.conf in multiple httpd instances. I am using: find ./ -name "...
0
votes
1answer
1k views

Colorize line number in grep

Is there a way to colorize line numbers when using grep with the -n option? For example, echo "hello" | grep -n lo outputs 1:hello where lo is colorized in red (being the match). Can I configure ...
0
votes
1answer
446 views

Reading a string till a key word and replacing from there with another string

I am new to UNIX and am practising shell scripting. I have an application where I need string searching and replacement. There are some lines in a file 1 and file 2. I have a search key word. If the ...
0
votes
1answer
487 views

Finding words with one vowel group

I am trying to use a command to find all words in a list of words with one group vowels. Like four, for and far, but also words like ore and or. What I got so far: grep -i ^[qwrtypsdfghjklzxcvbnm]*[...
0
votes
1answer
89 views

How to get ids from xml file into mysql?

I've got 8 xml files and need to do some work on these records in mysql. What is a good way to get these IDs into mysql? <?xml version="1.0" encoding="utf-8"?> <Records> <Record> ...
0
votes
1answer
166 views

Limiting grep search

Please help! Must use grep for this assignment. Must control grep function to search for a string strictly in a given field (Sadly no delimiters) Search field is characters 12-26. Must check if user ...
0
votes
1answer
225 views

Need to grep for specific lines from ongoing log and save it in some file

There is just one log, which will have info on certain devices, that i am upgrading. I use "tailf log" to monitor the log. Now, say, I am upgrading 10 devices, the log will go on populating lines ...
0
votes
3answers
61 views

Extract key value pair data from avro file into a rows and column form using unix command/shell script

I have a file with following dataset. {"table":{"string":"ABC"} "TYPE":{"string":"U"} "TS":{"string":"2019-08-19 12:45:12.006362"} "C_TS":{"string":"2019-08-19 07:45:13.631000"} "dpt":{"...
0
votes
2answers
938 views

Interactive commands with pipe and grep

As you know, there are commands such as top, watch, Airodump-ng, etc, that whenever you run, everything on the terminal change all the time. what I want to do is that run one of theses interactive ...
-1
votes
4answers
52 views

Copying first line of text to another text file

Before: file1 123 456 file2 foo testing After: file1 123 456 file2 foo testing 123 Any help would be greatly appreciated.
-1
votes
2answers
48 views

How to replace a matching string if n+2 line does not contain a particular string

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/...
-1
votes
1answer
100 views

Is it possible to use the -A paramter on a grep command to print every other line?

As I'm reading from a file, I want to grep every instance of 'x' from that file (line 1), along with the next line (line 2), and the line after that (line 3)... but then I want lines 6, 7, 10 and 11. ...
-1
votes
1answer
36 views

Variations of the Same Command Return Same/Similar Result

I'm working on a public server, which offers games designed to teach people Linux and ethical hacking skills. The goal of each level (so far) has been to find the ssh password to the following level ...
-1
votes
2answers
76 views

Recursively find ONLY the latest logs in all sub-folders and save to file

I am working on a RHEL7 box. I need to recursively find all the LATEST (and only the latest) .log files in each sub-folder below a certain hierarchy and list their full paths in a file 'all_logs.txt'...
-1
votes
1answer
159 views

Return single instance of multiple patterns from grep command

I have the output of a ps -ef command that returns hundreds of lines, and I need to grep for a pattern that is mostly identical, except for the number at the end, and have a single instance of each ...
-1
votes
1answer
42 views

Fetch a number of variable length from a file using pattern matching?

I have many files on UNIX and wish to fetch number in that file associated with a specified pattern. Most of the file will have a unique pattern in file like below some text abc some text abc some ...
-1
votes
1answer
40 views

Need to print the path for the texts on sub-directories (unix)

I need to print the path for the texts. Suppose I have below sentence: How are you? Now I want to know what is the directory/file or a path to this text.
-1
votes
1answer
124 views

Read file and write output in another file using shell script

My input file is: Employee e_id e_name 100 abc 101 xyz 102 pqr Salary e_id e_salary 100 12345 101 67890 Dependents e_id depp1 depp2 100 qwer tyui 102 asdf ghjkl I want the output line by line as ...
-1
votes
1answer
129 views

Searching for most recent file (Display Unique)

If i have a Folder structure with 10 Sub dirs Each sub folder has the possibility to hold a version of a file (Older or newer) "Poor folder structure." I was looking to use Find to locate all files ...