Skip to main content

All Questions

Tagged with
1 vote
2 answers
58 views

Need to make multiple multiline replacements in file

I have a file with multiple "paragraphs" like this: <type>TRANS</type> <attributes/> <specification_method>rep_name</specification_method> <trans_object_id/&...
Todd Porter's user avatar
-1 votes
1 answer
54 views

awk inside function causing errors

I'm trying to add the following to my .bashrc: cpu_info() { top -b -n1 | grep Cpu(s) | awk '{print $2 + $4}' } but bash is telling me: bash: .bashrc: line 131: syntax error near unexpected token `...
Mathew's user avatar
  • 243
0 votes
0 answers
71 views

Text processing grep and awk together on live script not working

I am using ssh to login to a remote server (Ubuntu), and then issue a command which outputs text/value each sec (live script). In the live output, I want to filter out the lines containing '...
SAM's user avatar
  • 1
-3 votes
4 answers
109 views

How to catch all lines of a repeating pattern and do some actions with the subresults

I am looking for a possibility to catch in a repeating text pattern all variable amount of lines between them and then do an action with it in bash. Example text: Total: text1 text2 Total: text3 Total:...
André Letterer's user avatar
2 votes
2 answers
63 views

Listing a certain part of filenames and their contents

I have a Linux machine with BusyBox, which has a directory called /data/var/lib/connman.  That directory holds some directories that I'm not interested in.  But it contains many .config files that ...
Norbert's user avatar
  • 121
0 votes
5 answers
160 views

How to add content to a file before the last } character using Busybox utilities?

There is a file with contents { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { ...
Maxim's user avatar
  • 119
1 vote
3 answers
122 views

print a text block / lines between pattern using grep or awk

My file file.txt looks like this: [NamesA] Andreas Alex [NamesB] Bernd Bruno [NamesC] Casper [NamesD] Doris I would like accomplish the following 3 different outputs, using grep or awk to use it ...
AKSNET's user avatar
  • 13
0 votes
5 answers
383 views

print characters between a specific pattern containing <>

i am asking for your help please. I reviewed a lot of sources and did some testing with awk and sed, but i can't get it to work. Below is a snippet of a config file which i could get an output via ...
AKSNET's user avatar
  • 13
1 vote
7 answers
313 views

Find all lines between two patterns, EXCLUSIVE of the second pattern?

Consider that I have the file listed below. I need to select all lines from every instance of the regex pattern Word A to before the regex pattern Word D. Word A Word B Word C Word D Word E Word F ...
RonJohn's user avatar
  • 1,144
-1 votes
2 answers
136 views

Grep a log file for SQL queries and their execution time

I have an application log file that also captures the execution time for each executed SQL statement, like below:- Sample logs: I 2023-11-15 07:18:00.743Z 1760463 37 ZVRwqItu6aw-b8eejMLI_gAAAAU 1@...
Arpit Jain's user avatar
-1 votes
2 answers
270 views

Filtering out values in a column that are zero

I have the following dataset: 071,36,035,08422,46217,00000,1,A,Broadalbin village (pt.),New York,18,46,46,46,45,45,44,46,44,46,43,43 071,36,045,29322,56209,00000,1,A,Glen Park village (pt.),New York,...
Mathew's user avatar
  • 243
1 vote
2 answers
197 views

Recursive pattern search - output formating: for each match file print out the specific file name "\n", line number, sentence matched "\n" in colors

I want a file content search command, under Linux so that: it will search on specified files, e.g: md, txt, htm. recursively from the folder and its subfolders, e.g: . the content search can be ...
user2718593's user avatar
3 votes
3 answers
110 views

How to recreate grep -f with awk

I have a large file with lots of unnecesarry info. I am only interested in section between edit and next and handle them as one entry. I manage to filter it down like this.... ' awk 'BEGIN {FS = &...
peti27's user avatar
  • 51
0 votes
4 answers
189 views

How to view a log file that's worth 10GB+?

The ways that I've thought of: If you get to reproduce the scenario in real time. Use tail -f application.log | tee /tmp/tailed_log But it's not sure that we'll get to reproduce the scenario in real ...
achhainsan's user avatar
2 votes
5 answers
584 views

Grep Multiple Pattern located in different lines and print in the same line

I'm trying to find a way to grep information in the file that located in the different lines and one of the pattern is contain pattern of date and time. below is the input unwantedtext unwantedtext ...
Ajie Pahlevi's user avatar
0 votes
3 answers
327 views

How do I use grep, awk, or sed to get a substring of a line up until a string literal?

I am trying to process a text file and omit a certain string literal if it occurs at the end of the line. E.g.: Source: ABC 123 DEF, characters I don't want GHI, these characters are ok Desired ...
Evan Harmon's user avatar
2 votes
2 answers
309 views

Why does awk concatenate strings from different lines

Good day. I'm trying to run a ping6 on IPv6 addresses pulled from /etc/resolv.conf.dnsph. It seems though, as if awk is stringing the IPv6 addresses onto one line. $ grep ^nameserver /etc/resolv.conf....
Bjoern's user avatar
  • 31
2 votes
2 answers
133 views

How can I select only successful values from leakcheck output?

I have these results that came from leakcheck. How do I properly exclude "false" results and still include the email using bash [email protected] {"success":false,"error":&...
noobwithskillissue's user avatar
3 votes
3 answers
730 views

Find files matching one pattern, but not another, using grep, awk or sed [duplicate]

I need to locate .php and .pl files that do not contain one string (e.g. aaa), but do contain another (e.g. bbb). I'm currently using this command: find /path/ \( -iname '*.php*' -or -name '*.pl*' \) -...
Krackout's user avatar
  • 2,742
4 votes
4 answers
691 views

grep multiple patterns with differing number of matching groups?

I'm trying to tally insertions and deletions from git diffs. I have the following, which when piped one or more strings of the form "4 files changed, 629607 insertions(+), 123 deletions(-)" ...
jawns317's user avatar
  • 143
0 votes
4 answers
183 views

Removing trailing newline from grep output

I'm looking for way to remove new line from grep output, I use grep -oP "changed: \[([^]]+)\] =>|'path': '([^']*)'" /path/to/file The output is like: changed: [hostname1] => 'path': '/...
shlco's user avatar
  • 1
2 votes
3 answers
214 views

Replace the last half in every line of a file with corresponding part in another file

I have two files A and B. Every line in both files is considered an item. The format of every item is fixed, consisting of a key and description, separated by a space. as shown in the example below. ...
echo's user avatar
  • 31
0 votes
3 answers
89 views

grep from a specific value to specific value

For example, I have a file with data: [2023-03-21 12:27:19 +0000] some_data [2023-03-21 12:27:19 +0000] some_data [2023-03-22 12:27:19 +0000] some_data [2023-03-23 12:27:19 +0000] some_data [2023-03-...
Mexanizm456's user avatar
3 votes
2 answers
760 views

How do you get the individual outputs of grep?

I've seen grep thrown around in plenty of answers but never wrapped my head around it. Now that I am playing with trying to get the content within HTML tags of a locally saved page from the internet, ...
Tim50001's user avatar
-2 votes
2 answers
91 views

Select all the text or characters between 2 text patterns that are repeating

Following is the sample .log file (there can be more lines in this) 2022 User abc (iii) 2023 defaa <party> ttt 2222221 User def (bbb) 20222 defaa <accoun> ttt 2222 User dddd (aaa) 3333 ...
John Doh's user avatar
3 votes
2 answers
396 views

Extract first word from txt file before ending with "/" sign in linux which contains "db" word in txt line

I have abc.txt file which contains two lines. I want to extract first word in line which contains db word in particular line. abc.txt: XYZ/db_abc.sql ijkl/tables/table_name/tl_abc.sql When I tried ...
Divyank's user avatar
  • 147
0 votes
1 answer
86 views

"grep -A" but with some lines removed

The problem The output of grep -A 4 davidson file.txt gives me: davidson 0 27 |r|= 0.00244 e= [-0.04073962 0.42777949 0.44157777 0.45997235 0.45997235 0.51613738 0.55005554 0.5538866 0....
Nike Dattani's user avatar
0 votes
0 answers
48 views

Script to find pdf files based on IDs

I have 500 IDs for students in an excel file (I have only one column for IDs) and I need to find the reports (pdf files) for each student among the 2K pdf files. These files are in one folder. Finally,...
Joman's user avatar
  • 1
0 votes
6 answers
224 views

search pattern and print in same line

I have a big .txt file in below format Pin name="AR_OP" status="f" Pref x=997.6800 y=2327.0400 side=N width=0.0400 depth=0.3750 / Layer id=1 -- Pin name="...
Shreya's user avatar
  • 139
0 votes
5 answers
158 views

How to bring the next line to the end of the first line using awk, separated by a comma?

I have downloaded some sequences from a publicly available database in .fa format. I want to generate a .csv file that contains the name of the sequence, and its length, separated by a comma. This is ...
Hrishikesh Hardikar's user avatar
-2 votes
4 answers
80 views

How to keep previous and current line if the previous line contains common text?

How to keep previous and current line if the previous line contains common text? I have a main file like this: Hello_world Anna Frank Jeremy Hello_earth Jessie James I would want 3 output files like ...
jovicue's user avatar
  • 11
-1 votes
3 answers
686 views

Searching in a CSV for multiple values and get the associated values from it

I have a file.csv "ItemNo","Name","Weight" "a001","Item a","1.1" "a002","Item x","1.2" "a003","...
R 9000's user avatar
  • 167
0 votes
2 answers
73 views

for loop with grep not returning record by record [closed]

I have the below for loop in my shell script: #!bin/ksh touch output.dat IFS=">>>" i=0 for stm in `grep "cpdctl dsjob run-pipeline --project " input_file` do echo "...
Jerry Jose James's user avatar
0 votes
2 answers
86 views

Trying to get a desired output from a text file

I have a output like this in a text file, where ^M represents CR Last login: Sat Jan 22 09:49:50 2023 from 10.1.1.1^M Cisco Router uptime exit -f Connecting user mike from 10.1.1.1 ******************...
rmb's user avatar
  • 871
2 votes
3 answers
50 views

How to collect both full lines, and matching part of line?

Is it possible to output both the full line and the matched parts of some line? Suppose I have this input low [ 0]: 0xffff0000 Interesting description A hi [ 0]: 0xffff00a0 Interesting description B ...
Moberg's user avatar
  • 187
2 votes
4 answers
637 views

Count lines ending in "*"

I have several files in a directory with this kind of content: Wood * Nails Large Hammer * Some names have a star after them, some don't. I have multiple files with such content. In each file a ...
math101's user avatar
  • 51
0 votes
4 answers
72 views

Awk multiline change

I have the following file for datadog ######################################## ## System Probe Network Configuration ## ######################################## # network_config: ## @param enabled -...
user9311662's user avatar
0 votes
1 answer
72 views

command for multiple input and multiple output with different extension

I am performing some operations using the grep, sed, and cut commands on a Linux machinete: zgrep -A1 "^module" *.v.gz | sed -n -e 's/^\(module \)*\(.*(.*)\).*$/\2/p' | cut -f1 -d"(&...
Santhosh Nayak D.'s user avatar
1 vote
1 answer
231 views

command for multiple input and multiple output

I am performing some operations using the grep, sed, and cut commands on a Linux machinete: zgrep -A1 "^module" *.v.gz | sed -n -e 's/^\(module \)*\(.*(.*)\).*$/\2/p' | cut -f1 -d"(&...
Santhosh Nayak D.'s user avatar
0 votes
3 answers
80 views

script using linux command to search word

I have the file, In the file data few lines have only one word, if such a case is present i want to print following line as the present line can I get some tips for this grep -E "module" ...
Santhosh Nayak D.'s user avatar
0 votes
1 answer
1k views

How to return true if string is found in a file using awk?

I have a file that looks like this: xxxxx,aaaaaa,abab21323,ccccccc I need a script that runs some command if a file contains a string given as a variable. If not, do some other commands. This is my ...
Claudio Del Prete's user avatar
1 vote
2 answers
299 views

Extract IP:PORT from a curl output

I want to get list ip:port from the curl output of curl https://www.gametracker.com/search/?sort=5&order=ASC I cannot post the whole output as it is very big, just posting the part from where we ...
ph3ro's user avatar
  • 378
1 vote
4 answers
149 views

Sed delete everything before and after characters

I'm running on android this Command: dumpsys activity activities | grep mFocusedApp Output: mFocusedApp=ActivityRecord{273535b u0 com.any.some/.app.AnyActivity t5595} Expected: com.any.some I need ...
Name F's user avatar
  • 5
-3 votes
2 answers
80 views

Grep first charcter from the string

10:30:01 10:35:01 There is a time in a format, where i want to grep: Case1: 1 from 10 Case2: 3 from 30 Output as 1 3 0 10-17-22 date in a format where i want to grep 10, 17, 22, seperately. Output ...
Siva  E5209's user avatar
0 votes
0 answers
78 views

I need to grep using string "degraded" and I want the output with Health State,Name, and Type. This is in Name Value Pair format

Name = Server1.domain.com Description = Tenant = Type = host Address = Netmask = OS type = VMware ESXi Ignored address = Host ...
ksv001's user avatar
  • 1
1 vote
2 answers
183 views

Divide a fasta file with scaffolds into same lenght files respecting the scaffold ID and the sequence

I am currently working with a large fasta file (3.7GB) that has scaffolds in it. Each scaffold has a unique identifier that starts with > on the first line and on the consecutive line it has the ...
Nadia Tamayo's user avatar
-1 votes
1 answer
228 views

Extract patterns from tsv table listed in the separate text file and add first 5 cells from the corresponding row

I am trying to extract some specific entries from a large tsv table using a list. I also need corresponding data in the first 5 columns. listfile.txt entry123 entry532 entry685 entry555 ...etc... ...
jkaymanm's user avatar
0 votes
1 answer
38 views

Save output of xdpdump to a variable

How can I save the output of xdpdump to a variable. I just want to save the number of packets captured. root@front:/home/ubuntu# timeout 2s xdpdump -i ens3 -w lol.pcap listening on ens3, ingress XDP ...
ph3ro's user avatar
  • 378
1 vote
5 answers
6k views

Print ONLY the next line after a match with awk

I have a command that prints the line directly after a match with several pipes using different tools like grep, awk, and tail. This works but it feels somewhat messy and uses multiple pipes to ...
AndG's user avatar
  • 303
-1 votes
2 answers
6k views

AWK or grep with cut. Need help cutting a field

I have this file and need to cut field 3 which should be cut - f 3. Right? I am using this code and its absolutely not doing anything for me. grep '^2014-' FileName | cut - f 3| less
B York's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
22