How to select the sentence with grep or awk? [closed] - bash

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
Domain name:
jewelleryfurkeeps.co.uk
Data validation:
Nominet was able to match the registrant's name and address against a 3rd party data source on 30-Nov-2022
Registrar:
Namecheap, Inc. [Tag = NAMECHEAP-INC]
URL: https://www.namecheap.com
what I want
Domain name:
jewelleryfurkeeps.co.uk
from above this I want only > jewelleryfurkeeps.co.uk

With perl:
$ perl -0nE 'say $1 if /Domain name.*?URL:\s+(\S+)/s' file
With awk:
$ awk '/^Domain name/{p=1;next} /^$/{exit} p{gsub(/ /, "");print}' file
With grep:
grep -A1 '^Domain name' file | tail -n1 | tr -d ' '
Output
jewelleryfurkeeps.co.uk

Related

how to cut specific word from a string in BASH [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
I have a string in shell script:
string1="0101122100635014,TEST123 22 SEP 06 PQR BC,14,25,0.05,,0915-1530|1815-1915:17,2022-09-30,1665066600,ABC:TEST123629500AB,10,11,90014,TEST123,26009,29500.0,BC"
I want to extract ABC:TEST123629500AB in shell scripting.
echo $string1 | magical command
output: ABC:TEST123629500AB
echo "$string1" | cut -d',' -f10
cut will give you part of string.
-d define the separator.
-f Specifies the column you want based on the separator

List folder contents and only show unique value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Is there a way to use the 'ls' command then then pipe the output to only show the unique item?
Here is the example:
ls /dev/disk/by-id
ata-ST500DM002-1BD142_S2AFE0JP
ata-ST500DM002-1BD142_W2AEDMQK
ata-ST500DM002-1BD142_W2AEDMQK-part1
ata-ST500DM002-1BD142_W2AEDMQK-part2
ata-ST500DM002-1BD142_W2AEDMQK-part3
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EEV65804
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EEV65804-part1
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EEV65804-part9
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EKK60289
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EKK60289-part1
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EKK60289-part9
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2ET092491
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2ET092491-part1
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2ET092491-part9
ata-WDC_WD5003AZEX-00MK2A0_WD-WCC3F2HAD1XC
ata-WDC_WD5003AZEX-00MK2A0_WD-WCC3F2HAD1XC-part1
ata-WDC_WD5003AZEX-00MK2A0_WD-WCC3F2HAD1XC-part9
As you can see in the output all but one of the items has the serial number and a -part# to it, but the serial ontop:
'ata-ST500DM002-1BD142_S2AFE0JP'
Does not. What I am trying to do is get the output to only show me the resits that do not have any other duplicate serial entries.The out out would be just the unique serial number.
ata-ST500DM002-1BD142_S2AFE0JP
Thank you.
Assuming these entries don't contain newlines, you may use:
printf '%s\n' /dev/disk/by-id/* |
awk '!/-part[0-9]*$/{arr[$0]; next} { sub(/-[^-]+$/, ""); delete arr[$0] }
END { for (i in arr) print i }'
ata-ST500DM002-1BD142_S2AFE0JP
Use grep with a regular expression : ls | grep -Ev 'part.*$'
$ ls test
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EEV65804 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EEV65804-part9 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2ET092491-part1
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EEV65804-part1 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2ET092491 ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2ET092491-part9
$ ls test | grep -Ev 'part.*$'
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2EEV65804
ata-WDC_WD5000AAKX-60U6AA0_WD-WCC2ET092491

Cut all till the end [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have an out put in the below pattern
["snaptuda-shv-22-lla1.example.com","snaptuza-shv-22-lla1.example.com","snaptuservice-proxy-shv-22-lla1.example.com"]
I used below command to strip the domains within the double quotes
cut -d"\"" -f2 file.txt
I got only the first domain , which was
snaptuda-shv-22-lla1.example.com
What I need is all domains till the end of the file , how can I achieve this ?
You input is json. For parsing json there is jq:
jq -r '.[]' filename
Or if the input comes from stdout, like this:
echo '["snaptuda-shv-22-lla1.example.com",...]' | jq -r '.[]'
snaptuda-shv-22-lla1.example.com
snaptuza-shv-22-lla1.example.com
snaptuservice-proxy-shv-22-lla1.example.com

Replace and remove characters in string, and add output as new column [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have an output from a program that I would like to process and If I pipe it to a file I get:
file/path#backup2018
file2/path/more/path/path#backup2019
file3/path#backup2017
And I want to process it so it looks like this:
file/path file.path
file2/path/more/path/path file.path.more.path.path
file3/path file.path
I have figured out how to make it with separate commands but would like a one liner.
$ awk -F# '{s=$1; gsub("/", ".", s); print $1, s}' file | column -t
file/path file.path
file2/path/more/path/path file2.path.more.path.path
file3/path file3.path
using sed
sed 's/\([^#]*\)#.*/\1 \1/g' file|column -t

How do I interpret this bash/awk syntax? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am making a sincere effort to master bash.
What would a line like below mean ?
ps -ef | awk '/ora_pmon_/ && !/awk/'
Thank you.
This means as follows.
ps -ef | awk '/ora_pmon_/ && !/awk/'
You are first getting the output of ps -ef which will have information of all processes running. Then by using a <pipe> (|) we send this output to the standard input of the awk command.
awk will check for lines, basically process names, having the string ora_pmon in them AND NOT the string awk. The latter is to exclude the process of this command which we do not want in output.
The correct way to do what you want though is just:
ps -ef | awk '/[o]ra_pmon_/'

Resources