Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [grep]

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

1
vote
1answer
27 views

lsof doesn't show up my djvu files

I am trying to print the djvu file names that are currently running on either okular or atril, but when I do lsof | grep ".djvu$" then I am getting no output in the terminal, where the same command ...
0
votes
2answers
65 views

Formatting output with printf piped in with xargs

I want to search my code base for ocurrences of a string, and then get the formatted output as filename, line number, and code lide. I got it as I wanted on the first line of the output, but the ...
0
votes
1answer
32 views

outputting 2 positions from same file into script and then echo

I have a file which looks like this: Sender Bob IP 10.1.1.1 Sender Alex IP 10.1.1.2 Sender Jim IP 10.1.1.3 10 lines like this in same format. I need to echo Name and IP. While iterating through my ...
1
vote
2answers
42 views

Matching exact number of digits in a string

Given a string, how can I find out that it contains exactly 7 consecutive digits number? Such as 1505082 or 1505082_CSE_322 but not 15050821 or 15050821_CSE_322 I've tried grep -Eq [0-9]{7} <&...
4
votes
4answers
439 views

how to check if the first line of file contain a specific string? [duplicate]

I need to write a shell script that find and print all files in a directory which starts with the string: #include. Now, I know how to check if a string is in the file, by using: for f in `ls`; do ...
0
votes
0answers
20 views

How to iterate pattern by other one?

I have the bellow output. I try to iterate same times the Date and Time: Month Day Year HH:MM:SS for each Application n.n string found it. =========================================================...
0
votes
0answers
51 views

Tail with case statement is not working properly [duplicate]

I want to monitor the logs continuously and echo the output if keyword appears then continues the monitoring!! My question is how to perform the below operation tail the logs if keyword[down] ...
0
votes
5answers
78 views

AWK from text with modification

I have the following file: hello there. let's try&ACCT=1&bla bla bla&EX=1118&anything ss &SERIAL=1011&DEAL=NO BLA BLA BLA&TOM=1&ACCT=2&LSLSLSLSL&none=1&EX=...
1
vote
1answer
46 views

Number of home directories in children of /

I have to count the number of children directories of / that contain one or more home directories. For instance, if john, emily and rick have their home directories in /home/john , /home/emily and /...
3
votes
1answer
22 views

FreeBSD - how to exclude some pattern with grep?

FreeBSD 11.0-RELEASE-p1 FreeBSD 11.0-RELEASE-p1 #0 root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64 grep (GNU grep) 2.5.1-FreeBSD Hi. I want to check availability of Asterisk ...
5
votes
1answer
366 views

Does grep --color default to =auto or =always?

What is the default color behavior for grep --color if no [=WHEN] is specified? The grep man page states: --color[=WHEN], --colour[=WHEN] Surround the matched (non-empty) strings, ...
1
vote
2answers
71 views

Concatenate a string with a variable in grep command

I have to search by this pattern: _20181106 20181106 is yesterdays date, so it has to be be a variable like TZ=aaa24 date +%Y%m%d How can I search a file with this pattern? I'm working with AIX
0
votes
1answer
26 views

Distinguish a command not a native second transmitter

suppose [root@iz2ze9wve43n2nyuvmsfx5z /]# find . -maxdepth 2 -type d | ls bin dev home lib64 media opt root sbin sys usr boot etc lib lost+found mnt proc run srv tmp ...
0
votes
3answers
39 views

Is it possible to print a search pattern result just until it hits a blank newline in terminal?

Say for example I have a file with contents like this: # TODO: Optimize this. alias bash='start bash' # FIXME: Just fix this. alias fix='there is something wrong with this What I want is if I ...
0
votes
3answers
36 views

Grep for searching two statements on the beggining and end of file

I have a file where i want to use grep to find what lines begin with 'X' OR end with 'xpto' I've got this, but it does not work. grep [^X][xpto$] test.txt Any ideas?
0
votes
1answer
26 views

How can I use grep in a loop and add new line of text each time to the same file?

I am trying to use grep in a loop and extract data from many files and then save them in a text file. Currently when I write grep sth > test.txt It writes it in the file test.txt, but when I run ...
1
vote
1answer
28 views

Getting email addresses from a file using grep with Regex not working?

So i have a file that contains emails like this : theirEmail@domain.com:theirUsername theirEmail@domain.com:theirUsername ... i want to extract emails that start with PA and then follow up with 6 ...
0
votes
1answer
28 views

Grepping lines which have range of number

I have few lines in my text file as below. I want to grep all the lines which have patterns like :100, :101 and :102 up to :199 . How to get those lines instead of searching like this. :100\|:101\|:...
0
votes
3answers
41 views

Remane filename by switching what is before and after an underscore

I would like to rename a number of files that have the following formatting: ABCD_20181102.jpg DEDE_2_20181030.jpg i.e usually 4 random letters, followed by an underscore and a date (year, month, ...
0
votes
1answer
31 views

Use negate ^ to get results which not contain specified charactres

I want to grep the files whose name not containing "^iX500" $ cat note_list ... /Applications/ScanSnap Manual.localized/iX500ScanSnapManual.app/Contents/Resources/manual/basic/EN/ix500/images_mac/...
-1
votes
1answer
36 views

Find files in specific directories

I have a college exercise which is "Find all files which name ends in ".xls" of a directory and sub-directories that have the word "SCHEDULE", without using pipes and using only some of the commands ...
0
votes
1answer
20 views

Filter last word after matching a string

I need to filter out some hexadecimal value from a return string of a command in bash for example: hexVal=`mmc extcsd read /dev/mmcblk1 | grep 'Max Enhanced Area Size'` Will return the value of ...
3
votes
1answer
249 views

Finding a string in a file on a file system using Grep

I need to do a search on a number of files in a file system to look for a string "RUSH2112". I have completed the following command however I am not sure if this is correct. I stand in the mounted ...
4
votes
1answer
148 views

cut command fields

I noticed these two different fields behaviors using cut command: bash:~$ var=`cat /proc/cpuinfo | grep 'model name' | uniq | cut -d ' ' -f 3,4,5,6,7,8 ` echo $var outputs Intel(R) Core(TM) i7-...
0
votes
0answers
21 views

How to multitail and grep for only one file?

I have set up a multitail with 4 windows (1 window to the left and 3 windows to the right). I would like to grep for the phrase "local" - but only for the first log file. I tried it like this but it ...
0
votes
2answers
23 views

exact string matching for multiple strings with grep

I am looking for exact string matches for multiple strings using grep. Lets say I want to find the following three strings in a large data file that has about 10 Million rows and 10 columns. I ...
1
vote
2answers
35 views

grep contents of one list with another

I have 2 files and I want to grep on them List1 ACY1 RPL3 RPL4 List2 1 ABHD14A-ACY1 2 ACY1 3 RPL34 4 RPL21 5 RPL3 6 RPL41 I tried something like this grep -Fwf list1.txt list2.txt ...
0
votes
2answers
39 views

How do I grep lines ending on a specific expression

I have a text file with 4 sentences and I want to grep the ones ending in "me", however when I do grep "me$" it doesn't work. Am I missing something? (I wanted the result to be the 1st, 2nd and 4th ...
0
votes
1answer
14 views

How to grep for line-separated strings containing a comma in a text file?

I have a textfile with the following strings with a comma in them: John,Smith Jane,Doe How can I grep * using this textfile? I've tried to use grep -xFf textfile * but I don't get any results even ...
0
votes
1answer
29 views

How to grep/sed/awk regex and color in man pages? [duplicate]

If I do man bash | grep read -c the output is 218. But I want to search only for colored regex in man. I still haven't find an approach. Any hint is welcome.
0
votes
4answers
76 views

Grep only gids from /etc/passwd [closed]

I want to grep only group IDs from /etc/passwd. Now I only came up how to grep the names, with: grep -oE '^[^:]+' /etc/passwd which gives me: [frynio@manjaro ~]$ grep -oE '^[^:]+' /etc/passwd root ...
-1
votes
0answers
22 views

Removing space from the specific fields of header line for extracting a correct file from a large original file

I have a challenge with probably a stupid thing, please be patient with me! I have a large file (15 columns, tab-delimited) that its head is like below: (Here, Flags column is empty, but not in the ...
0
votes
0answers
13 views

What software that I run uses AVX (or a specific assembly instruction)?

Let's say I want to find any libraries that use AVX, or the VZEROALL instruction? How could I go about doing that? I don't care if the AVX was hand written or compiled, I'll look that up later. I'm ...
0
votes
3answers
43 views

How to test for presence of a string before another string on separate lines in a file

I have a config file thus: a: 123 b: abc device: 1000 c: xyz [old] a: 120 b: xyz device: 200 c: abc The section "[old]" and everything below it is not always present. How do I determine if the ...
-2
votes
0answers
29 views

Im trying to answer a question and having difficulty myself? [migrated]

Create hardlinks instead of copying files with rsync Please note I cannot comment and I can only answer or Hijack answers because the sites flaws at inception. The question is not only how do I ...
0
votes
1answer
29 views

Error in grep command to exit from a Unix Script

I have a log file created while running a script. I want to check the same log file for any messages with 'Msg ....' and exit the code except with this 'Msg 2714'. So, I had added the below code ...
0
votes
1answer
38 views

How can I add some text after some sequence of text if this sequence matches certain criteria using Shell script?

I want to add a statement just after the text matching the conditions mentioned in a shell script, Below is my sample File(SQL File) : begin AFFECTED_ROWS := 0; UPDATE table_name SET column1 = ...
0
votes
1answer
43 views

How to extract a pattern of multiple lines

I am wondering how to extract a pattern of multiple lines, especially when this pattern is repeating in the text. The text looks like this: <tr> <td>Wife</td> <td>Pilialo</...
1
vote
3answers
67 views

Bash output two results next to each other

I have an out from xmllint and egrep that I would like to print two fields next to each other. e.g. (xmlinput) xmllint --format | egrep reference\|sourcefile <reference>ItemX</reference> &...
0
votes
3answers
68 views

grep AND feature from anywhere on the line [duplicate]

Is there any way for grep to have an AND feature? I mean something like this: I have these lines: I have this one line I don't have this other line I have this new line now I don't have this other ...
1
vote
1answer
76 views

searching letters in one line using grep and wc

I've created a text file with 1000 random uppercase and lowercase letters: cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 1000 > file1 How many times does the word 'cat' appear in this file, ...
1
vote
4answers
47 views

RegEx for matching strings in 2nd and 5th columns using grep

I have a file (test.txt) that contains string such as: name1,6.5.8.12,specs1,version1,['66.55.89.12'] name2,19.13.13.159,specs2,version2,['13.13.173.59'; '14.19.232.42'] name3,141.101.196.40,specs3,...
0
votes
1answer
41 views

Grepping on du -h for all the files that are larger than 1GB

So my disk is full, I am trying to grep for all the files larger than 1G. I tried searching for the word Sort in the man page of DU, but found nothing. du -h . | grep -E "^\d*\.\d*G" and also this. ...
0
votes
2answers
21 views

Copy values from a file to a new file only after certain characters

I have a file with the following format: Reading frame 3000 time 30000.000 ^MReading frame 3000 time 30000.000 mu 8.788e+00 <mu> 2.945e-03 and I want to paste the values which are ...
0
votes
2answers
77 views

Print the lines that only with all consecutive repeated characters

I have a text file and I want to print only the lines that have all their characters are consecutively reapeated at least two times or more. FOR EXAMPLE THE INPUT: 11 AAA 555227777 BBhh@@222 baabbb ...
1
vote
1answer
31 views

Using grep to find a word containing every letter a maximum of 1 times

I have a big text file where every word is placed on a different line, I need to find every word that contains any letter a maximum of one times (Examples of words I need to find: fingers, coal, ...
-1
votes
0answers
33 views

Using grep to locate and store a line

I am attempting to use a grep command to search a file for a particular substring and if it finds that substring, I want it to store the line that contains it in the variable presented. Assuming my ...
1
vote
1answer
44 views

How to remove pattern from line but return what remains?

If I run ip addr sho | grep 9000 it returns the interface that I need quick stats for: eth3: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 9000 qdisc mq state UP qlen 1000 However, I'd like to ...
1
vote
4answers
104 views

extract, cut, process strings in a bash script

I have basically 4 txt files with records such as FILE 1 localhost_access_2018-07-19.tar.gz:13 localhost_access_2018-07-20.tar.gz:17 localhost_access_2018-07-21.tar.gz:12 localhost_access_2018-07-...
1
vote
1answer
38 views

Running Script via Crontab With Different Result?

I have the following script: #!/bin/bash /usr/bin/echo q | /usr/bin/htop -C | /usr/bin/aha --line-fix | /usr/bin/html2text -width 999 | /usr/bin/grep -v "F1Help\|xml version=" > htop.txt It just ...