All Questions
76
questions
-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 `...
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(-)" ...
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': '/...
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
******************...
-1
votes
3
answers
471
views
How to match end of last string in file which does not end with punctuation
I'm trying to search a directory for files which do not end in a period. I'm trying to list the file name with the final ascii character which is not followed by period/ punctuation. I've looked all ...
0
votes
1
answer
775
views
Return content between corresponding brackets
I have a file with all type of brackets {}[]()- nested, open and close appropriately. I would like to return the content within the matching square brackets after the string (text:). The content of ...
2
votes
4
answers
1k
views
grep 2 words from specific csv column and count them
I am trying to find a better way to complete the following grep/awk query. The below is a trivial example of the question.
I have gotten to this point with my regex:
grep -Po ^(?:[^,]+,\s?){7}(Want|...
1
vote
2
answers
159
views
How I can grep data with some spaces and ignoring block?
I am trying to retrieve Local Address-port with port number in different block used by each IP-address in Foreign Address and PID/Program name) from the following and store it in a file:
I used:
...
0
votes
0
answers
35
views
Filter csv file with AWK passing a variable in the regex [duplicate]
I need to filter a very large csv file in the most efficient way. I already tried csvgrep but is not efficient timewise, so I'm now trying to use AWK for this task.
The csv file has a ; separator, and ...
0
votes
2
answers
680
views
Match a pattern and replace the value of the following key value pair
I'm trying to modify a file that contains sections like this:
[ policy_strict ]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName =...
-1
votes
1
answer
88
views
Select a particular portion from a html dump using regex based on a criteria using Unix commands
I am stuck with a question where I am supposed to display only those commands with a number of votes >= 1 from a dump of page http://www.commandlinefu.com using Unix commands. I am attaching a ...
0
votes
1
answer
453
views
Print text that appears after a substring match using awk in Perl
I have a multiple strings, as shown below, in a file MyFile-
1234|5|678|ABC|d|e| MyString - values: foo 1, bar 10%, baz 2/2, qux quux 10 sec, quuz 10km
How to print the substrings 1234 10 sec based on ...
0
votes
2
answers
2k
views
Searching for text patterns in a log file
I have a large log file where all the lines contained are of similar format. They can vary a bit, but the format until the first ] bracket is always exactly the same.
31.7.112.60 - - [26/Jan/2019:19:...
1
vote
4
answers
1k
views
Remove comments from file while ignoring quoted comment signs
I would like to remove comments starting with # from a file. I have tried the simpler approaches described in How can I remove all comments from a file? but I have a few additional rules:
A # does ...
0
votes
1
answer
48
views
test all line in a file with awk and grep and if it match put them in an other file
Here is my file test.csv
bonjour|b|french;deutsch|french
hello|h|english;russian|french
gutentag|g|german;polish|french
ciao|i|italian|french
I would like to test if the third split by | is french (...