All Questions
24 questions
1
vote
1
answer
323
views
Using grep to find all lines containing a character on an even position
So a line in the text file looks like this:
......-...-..--- (hello)
I want to find all lines that only have dots on the even positions. So I think I need to repeat searching for the regex pattern .\....
6
votes
1
answer
2k
views
Grep all strings that start and end with the same substring
I need to grep all lines that start and end with the same substring of at least 4 letters. The substrings can't overlap.
So imagine we have the input:
ABCDOOOPABCD
BBBBOLPOKBBBB
ACLMDJKAC
12345---...
1
vote
2
answers
38
views
substitute 2 substrings from a single line in a file into 2 different lines in a different file from command line
I have a text file with however many lines. One line is:
fixed_stringA = 123, fixed_stringB = 456
I have a second text file (again with however many lines). These 2 lines are in this order, in middle ...
0
votes
3
answers
2k
views
Piping ls to grep. Why does grep disregard the output from the ls command?
I am trying to use this command ls -p | egrep "\<[A-Z]+\>" to print all uppercase file and dir names with dir names having / appended. I do not understand why my command works even though I said ...
0
votes
1
answer
215
views
Bash User Input Search For Who is On Server If Statement Error Too Many Arguments
I am working on an assignment that requires me to accept user input to search for current users on the server and if the user input is online, I need to output the users name. If the user is not ...
2
votes
4
answers
4k
views
Getting only specific data based on name in text file
Let's say if my text file contains:
101 Adam
201 Clarie
502 Adam
403 Tom
and i want to write a command in the shell to only give me the numbers based of a specific name. For example, only ...
0
votes
1
answer
40
views
Outputting files into subdirectories
I want to run an egrep for several different patterns on a folder full of texts and output the results into corresponding folders. I'm also trying to make this neat and concise as this is a workflow I'...
0
votes
2
answers
93
views
One line shell command that finds all students in LEC05 and prints their first name in sorted order
For example suppose we have a file called input.txt which contains
100 John Doe LEC05 12356
132 Carol Bon LEC05 156
122 Cavar Liktik LEC01 136
...
This command should find everyone in LEC05 and ...
1
vote
3
answers
991
views
How do I make a substitution to `$0` but save the old value?
I'm trying to rename all files that start with an "m" to be the same name except with the first character (or "m" in this case) stripped away.
My strategy is to:
List all the files, with ls
Filter ...
24
votes
7
answers
67k
views
How does one extract a command's exit status into a variable?
I started learning Bash a couple of days ago.
I'm trying to obtain an exit status of grep expression into a variable like this:
check=grep -ci 'text' file.sh
and the output that I got is
No ...
1
vote
2
answers
97
views
Generating strings of words with space delimiters from cut statement
I am new to bash. When I run the following command:
grep "type" /root/myFile | cut-d'=' -f2
I get the following:
102
304
503
442
I want to store the contents of the first command into a variable ...
0
votes
2
answers
941
views
how to exclude string that include space by "grep -v" [closed]
I have a script that runs by using bash -c and I want to know how many process are running with that script.
$ ps ax | grep my_script_run | grep -v grep | grep -v "bash -c"
11121 ? S 0:00 ...
6
votes
4
answers
78k
views
grep all strings that start with a certain char, and finish with another char
I need to grep all strings that start with "[" and finish with a certain string, e.g. "apal". So all chars in between these 2 chars would be shown as well. Given an input such as:
[44060]apal223reaea[...
2
votes
2
answers
660
views
Autocomplete from grep output
How might I more easily use a filename found by grep as an argument to vim:
$ grep -r foo *
lib/beatles/john.c
lib/pantera/phil.c
lib/pinkfloyd/roger.c
lib/pinkfloyd/richard.c
lib/whitestripes/...
0
votes
1
answer
731
views
what grep -oh "[*?<com]" do?
I am trying to achieve something and in the experiment I came through following case , could somebody explain me how to understand whats happening.
echo " Agent process not running on www.raja....