All Questions
105 questions
0
votes
2
answers
133
views
print (only) line preceding a match
Consider a text-input that looks like this:
a
b
pattern
c
pattern
d
e
pattern
a
--
pattern
z
I would like to get only the lines that precede a match.
E.g. if my pattern is pattern, the output should ...
0
votes
2
answers
134
views
How to extract a text in between two patterns (potentially containing floating lookbehind) with only one invocation?
I'm trying to match any characters (except line break characters) in between xxx<1+ whitespaces>" and whitespace.
The format of the input string is the following:
xxx<1+ whitespaces>&...
2
votes
1
answer
349
views
How to Print, when columns have spaces - awk?
Problem:
desired columns have text with spaces SAMSUNG MZNLN128HCGR-000H1
undesired columns have text with spaces, see VENDOR = M.2 SSD
awk only printing the first word.
awk not printing the column ...
0
votes
1
answer
736
views
How can I combine "Search for multiple strings (patterns)" with "Print rows after a hit" in a string/search and output a common file?
I am using the windows version of grep "GNU Grep".
syntax: grep [OPTIONS] PATTERN [FILE...]
How can I combine different options with different patterns?
Both lines listed here work on their ...
-1
votes
1
answer
175
views
write a efficient for loop in bash for multiple files (.PDB files)
I have problem with this script:
#!/bin/bash
for filename in /home/hb/pg/ensemble/pdbs/P24941/raw_pdb/*.pdb; do
grep COMPND $filename | grep "CHAIN:" -B 1 | sed 's/COMPND//g' | sed 's/...
0
votes
0
answers
294
views
bash loop to create m3u file with sed awk grep
I am trying to auto create m3u file for my IPTV software with the help of sed/awk or grep command,but don't have much experience in this. expert help required to do this. working on Windows-10 PC ...
0
votes
1
answer
58
views
Linux - Find string and then end of section
I have an XMLTV file. I need to get all of the programme sections for a specific channel. An example snippet:
<programme start="2023031305000 -0400" end="2023031305300 -0400&...
0
votes
3
answers
286
views
Get a valid path with random directory name from a text file
How to to get the valid path from a string?
For example I have the following text in file.txt that will always generate with a random path using the following patern:
Some error occurred. rerun the ...
0
votes
1
answer
183
views
Insert new line if file contain string
I need to insert 'import packagename' to the line after imports. In files which contains the specific word.
What I try:
find iOS/Chat \
-type f \
-name "*.swift" \
-exec gsed -e "/...
0
votes
2
answers
5k
views
How to group and count all lines in a file that contain specific string
I want to filter all lines from a file that contain mySearchString and after that group them together and count them.
Example find all lines that contain 9791
AB-9791___Foo
AB-9791___Foo
DE-9791___Bar
...
0
votes
1
answer
286
views
Removing Duplicate from File
I have two files fileA and fileb
FILEA
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
5.5.5.5
FILEB
4.4.4.4
2.2.2.2
Output should be
1.1.1.1
3.3.3.3
5.5.5.5
Size of File A is around 60GB and Size of File B is 1GB
...
1
vote
2
answers
6k
views
Extract key from key-value pair
I have a file looking like that.
mke_version = "3.3.7"
msr_version = "2.8.5"
mcr_version = "19.03.14"
I want to print from file only key ...
1
vote
0
answers
503
views
grep and awk are not displaying output in terminal
When trying to grep Record in .txt file simply
$ grep 'Record' file.txt
$
it goes to the next line without any output or error (I've tried to write output in file, but it is empty)
I've tried also to ...
0
votes
1
answer
1k
views
grep for same occurrence more than once
Is it possible to grep or awk for more than 1 occurrence of the same string from a file?
awk '/$STRING|$STRING/' file
grep -e $STRING -e $STRING file
I tried other options but still not able to get ...
1
vote
1
answer
727
views
AWK/SED/GREP - print M lines after the Nth occurrence of a match
I am looking to display M lines after the Nth occurrence of a match. Actually I need to do this in order to split a file containing Nth <regex> always followed by M lines into Nth different ...
0
votes
1
answer
2k
views
grep for pattern including carriage return on a Mac
I want to search files for colon followed by carriage return followed by dash. I am using macOS (so it's BSD grep).
I would have thought
grep -l ":\n-" filename-pattern
would work, but it doesn'...
0
votes
1
answer
3k
views
How do i filter request from a json using curl?
so I recently deployed this Go app on the web https://20200329t202730-dot-ipengine-dev.appspot.com/ and the format that it shows the IP currently is
{
"ip": "169.254.1.1"
}
How do I only get the ...
0
votes
1
answer
66
views
Iteratively find all lines starting with X and move above next line starting with Y
I have a file like this:
Lorem ipsum dolor sit amet.
Consectetur adipiscing elit.
MATCH1 Quis autem vel!
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
MATCH1 Eum iure ...
2
votes
1
answer
84
views
replace keywords in a file by keywords\index{keywords} from a list file
I am trying to produce index entries in a LaTeX file under Linux. I have two files: file1.txt has all the index entries
cats\index{cat}
dogs\index{dog}
elephants\index{elephant}
rats\index{rat}
The ...
1
vote
2
answers
324
views
Remove specific string from file
output.txt
1.1.1.1:22/ does not support password authentication. [ERROR] target ssh://2.2.2.2:22/ does not support password authentication. [ERROR] target ssh://3.3.3.3
i want to remove string :22/ ...
0
votes
1
answer
92
views
Why is my bash shell script changing spaces to linefeeds?
I started out writing a simple bash shell script to find duplicate files within a given directory using SHA1 to detect matches. Everything worked until I encountered file names with spaces. The ...
0
votes
1
answer
38
views
Merge lines which are not in proper
I have the lines similar to below.
[1] 07:37:38 [bb..], qw, Exited with errojjjvice not known
[2] 07:37:39 [bfb.], fg, , This is FILE1, Stderrle or directory
[3] 07:37:39 [SU..], b b, ,, Stderr: bash:...
0
votes
1
answer
350
views
permission script with stat command trouble awk special character
I want to number of permission directory and write a script for equalizing two different server directory. I have use stat command.
command: stat /var/ | grep -i 'Access: ('
output: Access: (0755/...
2
votes
2
answers
1k
views
replace number with star specific pattern for whole file
In my file I want to replace number to *
Example:
data[0] ---> data[*]
I have data[0] to data[127] and also want to do for the whole file.
So how can I do only for number?
I tried with command
...
1
vote
1
answer
357
views
mac: concatenate contents of text files across many directories; append directory names to corresponding text file contents
In the following directory structure:
directory1
-subdirectoryA
---fileA.txt
-subdirectoryB
---fileB.txt
subdirectoryC
---fileC.txt
I would like to generate a text file containing the following ...
1
vote
1
answer
101
views
Take a file of regexes and return the first match for each in another file
I have two files. a.txt has a list of regexes, separated by newlines. b.txt has lines, some of which match the regexes in a.txt.
What I want: A command (grep, probably) that will take the two files, ...
3
votes
2
answers
740
views
How to get a specific string value from an Apple System profiler SPHardwareDataType
I'm using Bash to rename computers en masse using a part of the serial number, which is pretty easy, but my client has requested that the manufacture year of each machine be appended to the end.
...
1
vote
2
answers
8k
views
How can I output iperf results for only Interval and Bandwidth?
I am trying to get the output from the command
iperf -c 10.0.0.1 -t 3600 -i 2
And only need the Interval and bandwidth fields listed for the entire hour of logging.
I haven't used grep or awk in ...
1
vote
2
answers
144
views
Search a line(string) between other two diferent lines
I'm searching for one liner command (in best way) that can find if specific string/line is presented between other two lines. I search for it and I only found commad to get content between two lines, ...
-2
votes
2
answers
169
views
find string and check for second
Every file have first line that start with a 1 b followed by unknown_string
and remaining lines starting with c followed by unknown_string
I want to check the string AFTER the a 1 b is present in any ...
1
vote
1
answer
2k
views
How to extract a segment of a binary file based on starting and ending hex strings
I have a large binary file (several hundred GBs) and I want to extract a segment from it. I know the hex strings of the beginning and ending points.
0
votes
1
answer
179
views
Break down the following bash script?
I need help breaking down the following bash script, to understand what the author was trying to do. The script is meant to search a log file for data and then compare it to an email log file. ...
1
vote
2
answers
312
views
Filter lines if number of string occurrence found?
Need to filter and show log lines, if line contains exactly 2 commas, and does not contains a specific string. Which linux command need I use, awk, grep, what is the expression?
For second condition ...
-1
votes
1
answer
1k
views
regex to match any combination of text of indeterminate length
A Windows SyncToy logfile contains several thousand lines of the form:
xxx ... C:\zzz. xxx ...
and
xxx ... zzz\. xxx ...
where xxx can be a string including any printable character including ...
1
vote
1
answer
1k
views
For each output of grep execute multiple commands
First:
sudo netstat -nptc | grep -oP "\K[0-9]*(?=/perl)"
The above gives me the pid as they are started, so it is constantly running.
Second:
For each output of the first command above I want to ...
2
votes
3
answers
60k
views
Linux command for exporting output to a csv file in separated columns
I am wondering when using Linux command line, how can I output a result i grep to a CSV file in different columns.
Here are the columns i grep from 'last' command
The final format, I would like to ...
2
votes
1
answer
1k
views
Sed/awk/perl match all prefixes of a given string
I'd like to match all lines in a file that either my word is a prefix of, or the line is a prefix of my word. For example searching for "abc" should match:
a
ab
abc
abcd
abcxyz
but not:
...
-4
votes
2
answers
126
views
How to delete line which have only number using vim/grep/cat/awk?
I have this text
which will be considered further in Chapter 6
Siannis et al., 2005
Crowther and Lambert, 2013a
Schumacher et al., 1994
2014
df=4
2005
2005
0, 1
4....
0
votes
1
answer
755
views
How to remove partial duplicates in bash?
How can I remove partial duplicates in bash using either awk, grep or sort?
I did try sort -u FILE | uniq -w20 but it's not really reliable.
Input:
http://www.website.com/1.file
http://www.website....
0
votes
1
answer
21
views
Getting the details of application versions of all vz nodes through command line
Finding application details of all the openvz containers
Needed to find the versions of applications(like cpanel, apache,php, mysql, ruby and rails)
1
vote
1
answer
244
views
receiving a bunch of (incomplete)s during a GREP and AWK command
when I use this command:
arp -a | grep "192.168.0.19" | awk '{ print $4 }'
I receive these results... the ff:ff mac address is what I want, but why do I get a field of (incomplete)s? All I want is ...
-1
votes
3
answers
346
views
How copy or display unique entries from two text files in linux or in windows
I have two files and the format of the files is variable=value or # or # variable.
Values of all variables is either unset;yes;mod
I want to copy all entries from these files to another file and only ...
1
vote
3
answers
122
views
Display file contents if it has corresponding line number
I have two files in the following format:
File A
4
5
8
9
File B
1 text
2 text1
3 text2
4 text3
5 text4
6 text5
7 text6
8 text7
9 text8
What I want to have for my output is just the following (the ...
0
votes
1
answer
101
views
How to Check value for an input element after fetching contents of page using cUrl
I am trying to download a page using cUrl. I have saved the page to a file and I then grep on it to extract the value of the text field. The text field appears multiple times and I just need one value....
-1
votes
1
answer
44
views
Oneliner to get the list of filenames which have last line (or line on position X) matching certain pattern?
How to get the list of filenames which have last line (or line on position X) matching certain pattern?
We are looking for oneliner.
1
vote
1
answer
158
views
Remove a certain part in a text file
I got the file, text.txt. In this file I have written:
"test"
"okay"
I want to remove the " part of this file, how'd I do this?
3
votes
3
answers
3k
views
Filtering and splitting huge file based on column Windows
I have about 2 TB worth of data files formatted like
12/20/2015 somerandomdata
12/20/2015 somerandomdata
12/20/2015 somerandomdata
12/20/2015 somerandomdata
12/21/2015 somerandomdata
12/21/2015 ...
12
votes
3
answers
24k
views
How to find files within a size range?
Please suggest a way to find all the zip files which are more than 60 MB but less than 70 MB in size using the find command.
1
vote
1
answer
283
views
How to find the last 2 characters of Chinese names with command lines tools?
I have a list of Chinese names, some of them have 2 characters, others may have more or less, like following:
I want to use some command lines tools, to find the last 2 characters of each. If doesn't ...
0
votes
1
answer
150
views
Awk eqivalent to grep -C <num>
I want to print 5 lines of context around each line that matches "foo" but not "foobar".
I can do the match easily enough via <output> | awk '/foo/ && !/foobar/' but I can't figure out ...