grep for a string from URLs of different lengths [closed] - bash

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 1 year ago.
Improve this question
I have a text file (foo.txt) containing a number of URLs. Each URL contains a file ID:
www.url.com/etc/one/two/72f66_59875c1ffb57b5992-b18/something/maybe/
www.url.com/etc/8823cd1-ab9532a5dc74cc904cc6bd3e2/perhaps/
www.url.com/etc/something/8407fb_80bbb9c0d/1/2/6/
My expected output is just the file IDs:
72f66_59875c1ffb57b5992-b18
8823cd1-ab9532a5dc74cc904cc6bd3e2
8407fb_80bbb9c0d
I don't yet completely understand how to leverage grep to make this happen. I have been humbled.

Those look like all hex digits, so
grep -oE '/[[:xdigit:]_-]{15,}/' foo.txt | tr -d /

Related

tracing multi-line commands 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 3 months ago.
Improve this question
Using the uprobe example for hooking bash's readline gives one line at a time. What/How should I hook to get multi-line commands?
I tried hooking add_history but that gives me only one line.
Example input:
cat EOF
x
<< EOF
ls \
| grep

Cutting columns in many files - Bash - how do I save the results in different files? [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'm writing a script that would allow me cut columns number 2, 4, 5... in many files.
I know that I have to use awk to print only required columns. But how do I save the results in different files? What do I write after > ?
with gawk you can use FILENAME variable, and in your awk codes, redirect the required columns to FILENAME"_new" for example.
awk '{... ;print $2,$4,$5> FILENAME"_new"}' *.csv
You may want to add close(FILENAME"_new") if you have many files.

cutting a particular part of a line without using grep command [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 8 years ago.
Improve this question
RPO.RE4_SND_MSG_RECO_Q_n_message
i have an line like this. I would like to cut till RPO.RE4_SND_MSG_RECO_Q . when i used
cut -d '_' _f4
it gave oly RECO as output .please help me Newbie to unix
You can use:
s='RPO.RE4_SND_MSG_RECO_Q_n_message'
cut -d_ -f1-5 <<< "$s"
RPO.RE4_SND_MSG_RECO_Q

Reuse of the same variable wit using echo and cut [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 8 years ago.
Improve this question
I'm try to make a script for checking some ethx.
If the eth is up and connected my script is working
When its not working I have a problem.
RESD=$(ssh -q vmx#$1 cat /sys/class/net/$3/dormant)
I get in RESD the following result:
cat: /sys/class/net/eth3/dormant: Invalid argument
I want to put in RESD now the first letter.
How can I do this?
Thanks
As per the comment above, this what you want to do: RESD=${RESD:0:1}? This is pure bash equivalent of RESD=$(echo $RESD | cut -c1).

Unix: Trying to increment a calender year and display [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 9 years ago.
Improve this question
I have a unix assignment and What I have isnt working right. It doesnt format like the normal "cal" function.
#!/bin/bash
d=`date '+%Y'`;
$((++d));
calstr=`cal $d`;
echo $calstr;
You don't need the $ in line 2, and you need to wrap the $calstr in double quotes:
#!/bin/bash
d=`date '+%Y'`;
((++d));
calstr=`cal $d`;
echo "$calstr";

Resources