How to concatenate yt-dlp output of "--get-id" and "--get-title" flags on the same line - flags

I am new to using yt-dlp and would like to have as a response to the command "yt-dlp --get-id --get-title <playlist_url>, both the output result of "--get-id", concatenated with the output result of "--get-title" on the same line.
When I run the above command, the results appear on two separate lines.
I would like someone's help because I need these results to put in an Excel spreadsheet, with the ID in one column and the title in another.
I've tried several other ways but without satisfactory results.
Thank you for any help.

Related

Scraping specific hyperlinks from a website using bash

I have a website containing several dozen hyperlinks in the following format :
<a href=/news/detail/1/hyperlink>textvalue</a>
I want to get all hyperlinks, and their text values, where the hyperlink begins with /news/detail/1/.
The output should be in the following format :
textvalue
/news/detail/1/hyperlink
First of all, people are going to come in here (possibly talking about someone named Cthuhlu) and tell you that awk/regex are not HTML parsers. And they are right, and you should give some thought to what they say. Realistically, you can very often get away with something like this:
sed -n 's/^.*<a\s\+href\=\([^>]\+\)>\([^<]\+\)<\/a>.*$/\2\n\1/p' input_file.html
This tells sed to read the file input_file.html, find lines that match the regex, replace them with the sections you specified for the output, and discard everything else. The result will print to the terminal.
This also assumes that the file is formatted such that each instance of <a href=/news/detail/1/hyperlink>textvalue</a> is on a separate line. The regex could easily be modified to accommodate different formatting, if needed.
If all of the links you want happen to start with /news/detail/1/, this will probably work:
sed -n 's/^.*<a\s\+href\=\(\/news\/detail\/1\/[^>]\+\)>\([^<]\+\)<\/a>.*$/\2\n\1/p' input_file.html

Use bash to extract data between two regular expressions while keeping the formatting

but I have a question about a small piece of code using the awk command. I have not found an answer/solution anywhere.
I am trying to parse an output file and extract all data between the 1st expression (including) ATOMIC and 2nd expression (excluding) Bond. This data is to be sent to a new file $1_geom. So far I have the following:
`awk '/ATOMIC/{flag=1;next}/Bond lengths in Bohr/{flag=0}flag' $1` >> $1_geom
This script will extract the correct data for me, but there are 2 problems:
The line ATOMICis not extracted with the data
The data is extracted and appended to a single line. I want the data to retain the formatting from the parsed file (5 columns, variable amount of lines). Please see attachment to see a visual. Visual Example Attachment. Is there a different way to append data (other than >>) so that I can keep formatting?
Any help is appreciated, thank you.
The next is causing the first match to be skipped; take it out if you don't want that.
The backticks by themselves are a shell syntax error (unless your Awk script happens to produce valid shell commands). I'm guessing you have a useless echo or something like that in your actual script which disarms the error, but instead produces the symptoms you describe.
This was part of a code in a csh script and I did have an "echo" in front of this line. Removing the "echo" makes it work perfectly and addresses the 2 questions that I had.

Extracting data from text file after 2 conditions have been met

I'm working on a bash script at the moment which extracts data from a text file called carslist.txt, which each car (and its corresponding characteristics) being on separate lines. I've been able to extract and save data from the text file after it's met a single condition (below for example) but I can't figure out how to do it for two conditions.
Single condition example:
grep 'Vauxhall' $CARFILE > output/Vauxhall_Cars.txt
output:
Vauxhall:Vectra:1999:White:2
Vauxhall:Corsa:1999:White:5
Vauxhall:Cavalier:1995:White:2
Vauxhall:Nova:1994:Black:8
From the examples above, how would I extract data if I wanted the conditions Vauxhall and White to be met before extracting them?
the grep example above asks for Vauxhall to be met before pulling and saving the data, but I have no idea how to do it for 2. I've tried pipelining the command as Vauxhall | White but after that I was out of ideas.
Thanks in advance.
I would recommend to use awk, like this:
awk -F: '$1=="Vauxhall" && $4=="White"' input.file
As I'm using : as the field separator, I simply need to check the values of field 1 and 4.

how to get html from plain formatted text?

I have an array that looks like
Ant run name : Basics of Edumate
Overall result : pass
Ant run took: 4 minutes 13 seconds
--------------------------
Details for all test suits
--------------------------
login : Pass
AddCycleTemplate: Pass
AddCycleTemplate: Pass
AddAcademicYear : Pass
AddAcademicYear : Pass
AddCampus : Pass
Is there any easy way how I can convert this in ruby into html that keeps the formatting?
If these are the only kinds of lines you will ever see, then you could certainly write a Ruby script that does the following:
First, output a doctype declaration, an opening html tag, an head section, an opening body tag, and an opening table tag with whatever style you like.
Read your Ant output line by line. If the line has a colon in it, split it on the colon and output a table row with two columns (each side of the split). If the line does not have a colon write its text as colspan=2, perhaps with a style indicating a large margin-top and margin-bottom, except if it is all dashes in which case you should ignore it.
Output HTML to close the table and the body.
This is certainly a hack and not a general solution by any means, but hey if you are writing a tool just for yourself so you can have some pretty little ant outputs, go for it. This is no more than 20 lines of Ruby. Write it to read from stdin and write to stdout so you can pipe your ant output to it!
if you don't care about formatting, just encapsulate the entire thing in <pre></pre> tags and you're set. All new lines and whitespaces will be preserved and default font is a monospaced one.

Ruby outputting to the same line as the previous output

I am writing a Ruby script to generate a CSV file.
My understanding is that each line in a CSV file is a row in a table.
Right now my script generates something looks like this
Vancouver, Calgary,
Routes1,
Routes2,
Routes3,
Vancouver, Toronto
etc,
etc,
etc
but I need it to make it look like this to import it to a DB
Vancouver, Calgary, Routes1, Routes2, Routes3
Vancouver, Toronto, etc etc etc..
My script works by looking up Vancouver and Calgary from raw data that contains the locations of the routes in different files. Then the script goes to those files to look for actual routes. Each time it finds a route (eg. Route1), the script outputs it using "puts" method.
The problem is that every output is on a new line.
Is there a way to suppress the new line command when using "puts" command?
Yes, use print var instead; puts automatically appends a new line, print doesn't.

Resources