All Questions

Tagged with
Filter by
Sorted by
Tagged with
0
votes
1answer
24 views

Use reverse i search to cycle through only commands matching pattern

The contents of the command history file using history | less is: 555 ls 556 ls -a 557 echo "hello" 558 echo "hello again" 559 cd 560 pwd 561 echo "hello hello" 562 ls 563 echo "hello hello hello" ...
0
votes
4answers
46 views

Use grep to search for words beginning with non-word characters

The contents of the file testing.txt are: ls -a cmake --verbose verbose I want to use grep to look through this file and find only the word beginning with "--" i.e. the word "--verbose" However ...
3
votes
3answers
115 views

Extract lines that have two or more dots

I need to extract (or count) the lines (in a file) that have two or more dots. The lines should not start with dot (it’s OK if they end with a dot), and there must not be two dots in a row (i.e., the ...
4
votes
2answers
376 views

Searching for a string that contains the file name

I have a large set of files in a directory. The files contains arbitrary text. I want to search for the file name inside that particular file text. To clarify, I have file1.py.txt (yeas, two dots .py....
3
votes
4answers
404 views

How to remove trailing forward slash

For each line in my file, if the line ends with / I want to remove it. How to do this? My attempt: sed -e "s/$\/$//" myfile.txt > myfile_noslash.txt Did not work.
-1
votes
1answer
34 views

Search for a string in lots files in a directory, if found, save the file name and line

I have several files, with different names. no specific format for them. But all are .txt. For example: example.txt flower.txt abc.com.txt They are in the same directory. I want to search for a ...
-1
votes
1answer
30 views

I want to pull specific data from a text file

I have a file called MemoryReport.txt . Somewhere in the middle of each line, it says Limit:. I would like for a script to copy only lines that says Limit:1 and exclude all others and print to a ...
1
vote
0answers
51 views

How can I search a text file Google-style? [closed]

As you know, Google is very smart with searches, while the best search terminal tool I have ever seen just allows you to search with regexes. Is there a tool to search text more like a search engine? ...
0
votes
2answers
64 views

How to extract string between the first occurrence of : and a colon

I have a long file that I need to reprocess for entering it into database. The file's data are in this format: Error for: 111.222.55.1,[ZXX: Error message] some text (_xxx.c:833) Error for: 198.243....
0
votes
4answers
274 views

Grep a pattern from a file and get that whole word, not just the pattern

List item I/P: abcd_Server1 CCDDomain defg_Server1 GGFDomain kdkhs_Server1 CCDDomain abce_Server1 CCDDomain dgdg_Server1 CCADomain dfdkhs_Server1 GGFDomain I need to search for the word "Domain" ...
-3
votes
2answers
483 views

Find and Extract Text inside Strings [closed]

I want to find text inside a string Pattern from a data file and extract them in a text list using shell or AppleScript. An example inside XML: node file="source_files/ (var1) .mp3" Another example ...
0
votes
3answers
73 views

count country code in a file and save a file command or bash script

Situation: I would like to write bash script or a command which will count only country code in /var/log/mywebsite.log how many of them then save a file. I would like this script to check Linux time ...
0
votes
1answer
42 views

How do I extract a portion of an SQL statement for the purposes of searching and replacing?

I'm using bash shell attempting to do a search and replace. I have a file of lines that look like ... INSERT INTO currency (name, code, symbol) VALUES ('Baht', 'THB', '฿'); ... and I want to ...
0
votes
3answers
161 views

Explode Depth Search in UNIX

I've a following data in file which has user and supervisor relationship. user |supervisor |id -----|-----------|---- a | b | 1 b | c | 2 c | d | 3 e | b | ...
2
votes
1answer
520 views

How do I replace tokens from one file with data from another?

I'm using Amazon Linux with bash shell. I have a file with comma delimited data, where each row looks like this 2049,576804C7DF554416A9EA25B2A5A81514,X, Then I have a second file, with comma ...
2
votes
1answer
337 views

read patterns from file1 and search them iteratively in file2

I'd like to read patterns from file1 and search them iteratively in file2, printing the matched line plus 3 rows, and print them to file3. Now I am doing: cat file1 | while read line; do awk '/$...
5
votes
4answers
6k views

Print only the Nth line before each line that matches a pattern

I'm trying to print only the <N>th line before a search pattern. grep -B<N> prints all the <N> lines before the search pattern. I saw the awk code here that can print only the <N&...
1
vote
2answers
87 views

How do I find a substring in a command line?

I have a few files that contains a similar entry like as follows: {"result":[]} {"result":[{"alternative":[{"transcript":"I win","confidence":0.87958056},{"transcript":"when"},{"transcript":"Schwinn"}...
13
votes
3answers
3k views

Binary search in a sorted text file

I have a big sorted file with billions of lines of variable lengths. Given a new line I would like to know which byte number it would get if it had been included in the sorted file. Example a\n c\n ...
0
votes
2answers
102 views

Given a string to match in a file how to output the specific line(s) which doesn't occur at a specific distance from the matched string?

The title doesn't grasp the body much. Edits are requested. I've a string android.permission.CAMERA to match in the output of adb shell dumpsys package. My goal is to list the package name of the ...
5
votes
2answers
3k views

grep string where next line does not contain string

I want to search all files inside a directory and its subdirectories for lines containing a certain string, but I want to exclude those results that contain a different certain string in the line ...
1
vote
4answers
43k views

Find text in a file and copy it to another file

Is there any command in Linux to find text in a file and if found then copy it in another file? Using sed -i we can find text but how to copy whole line in another file?
10
votes
2answers
19k views

How to search for text in a file ignoring newlines?

I'd like to search for text that may be split over several lines in a file. A grep that would ignore line breaks and return the matching span of lines. e.g. I would be searching for is an example ...
1
vote
2answers
97 views

How to show searched lines as well as number of occurrence of searched string?

I am working on a script which will show all the results and their count on the console based on a particular string . Example: Suppose I searched for a string called "ERROR", I got the below results,...
1
vote
1answer
160 views

How to filter a basic csv by columns

How do I filter by third column of the following file list.txt [[ list of people ]] billy baxter - @baxter - b.baxter@woods.com james woods - @woods - j.woods@someother.com I currently have cat ...
2
votes
2answers
114 views

Search and Replace question

I need to find all occurrences of AAsomeArbitraryStringBB and replace it with CCsomeArbitraryStringDD. So AAHelloBB Text AAByeByeBB becomes CCHelloDD Text CCByeByeDD. It's important to note that ...
24
votes
3answers
10k views

Unix command to check if any two lines in a file are same?

Is there a unix command that can check if any two lines in a file are the same? For e.g. Consider a file sentences.txt This is sentence X This is sentence Y This is sentence Z This is sentence X ...
1
vote
2answers
179 views

Mailing out a customised content based on specific search in a logfile

Using below test.sh, I am getting result in dump.txt as below: test.sh: #!/bin/bash #"Maxl-script" zone starts..... essmsh -l admin password -s localhost -i << EOF spool on to 'dump.txt'; ...
1
vote
1answer
886 views

Binary search for a failing line

git has bisect run to figure out which revision an error was introduced. I have a big file (100GB) and at least one of the lines is bad, but the program I have to check it with will not tell me which ...
3
votes
3answers
2k views

Help searching in files for regex patterns, recursively, with specialized output

My problem is that I need to: Find all lines matching regex_pattern in all files (deep search) in a given root directory For each line that matches, output: File name Line number containing the ...
0
votes
1answer
2k views

comparing lines with awk vs while read line

I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line ...
9
votes
2answers
4k views

Find all files with a Python Shebang

I'm trying to run a PEP8 check against a large source tree. The tree is comprised of a mix of files in various languages. The idea is to check all the Python scripts without having to explicitly list ...
1
vote
1answer
57 views

Replaced matched text in Vim with pattern

Here's a minimal example of what I'm trying to do. Start with: "this") "that") [hundreds of lines like this] End with: "this",&this) "that",&that) [hundreds of lines like this] I have gotten this ...
6
votes
4answers
2k views

Look for English word in a file via terminal

How to find and print out English words contained in a file via linux command line?
4
votes
3answers
238 views

Smart way to perform a similar replacement (not simple enough for diff) in multiple files?

I have a bunch of files (45, so too many to edit them manually without going crazy) which all require the same changes (as seen in the three diffs at the end of this question). Most tools used for ...
4
votes
1answer
4k views

How to do multiline search and replace text (delete) recursively

I want to go recursively through a directory and search for specific content in all files. The content should then be replaced if found. With a single line I would make something like this: find . -...
3
votes
2answers
1k views

remove only specific text occurrences from string using sed

I have a text file that contains many rows of this sort of thing: /*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36'; Is there a way that I can use sed to remove ...
3
votes
3answers
2k views

Longest common substring using grep

I have a huge text file called dictionary.txt with entries like ABC_SEQ_NUM This represents.... ABC_RANK This represents.... ABC_BSC_ID This represents... PQR_TA_DATE_AF This ...
1
vote
1answer
285 views

Tools to dump entries from arbitrary sets of log files between 2 dates

I had a outage incident a few days ago and the support team has asked for any available logs for the period, while thinking about how to do this, it occurred to me that it would be generally handy to ...
8
votes
3answers
9k views

How to search and replace multiple needles by one word via one expression?

Assume you have a text file: foo fnord bar bizz foo poit And now I would want to replace both "foo" and "bar" into "narf". I know I could use: sed -e 's/foo/narf/g' -e 's/bar/narf/g' fileName ...
6
votes
4answers
508 views

Fastest way to determine if two sorted lists contain unique elements

I have two sorted files A and B where the size of A is much greater than B, e.g. A is 100GB while B is 50MB. I want to quickly determine if there are any lines in B that are contained in A, stopping ...
5
votes
5answers
4k views

How to replace a list of placeholders in a text file?

I have a text (configuration) file, but the program that reads the file unfortunately doesn't allow using any kind of variables. So I'd like to use a preprocessor that replaces a set of placeholders ...
5
votes
1answer
1k views

Is there a search utility which can binary split search a large sorted (sequential) text file?

Yes, I know it sounds odd. Sequential and Binary-splits don't mix.. That is unless the sequence is the byte offset within the file itself... I've scrambled together a binary split search in bash ...