We will present a more special method of using the Linux command line.
This method comes in helping those who need to text or HTML content.
In fact, a combination of Linux commands to get an output.
Suppose we have a list of jpeg files in folder image.
They should exist into HTML to be displayed.
As we know an image has the form:
1 | <img src="image/name_of_jpeg.jpg" alt="" /> |
The list of the file is :
1 | 11.jpg,12.jpg,13.jpg,14.jpg,15.jpg |
My method uses two commands: ll and awk.
First, I will display files:
1 2 3 4 5 6 | $ ll | awk '/jpg/ {print $9}' 11.jpg 12.jpg 13.jpg 14.jpg 15.jpg |
I created one variable f1.
In these variables put the beginning of each line:
1 | f1=‘<img src="image‘; |
We add two sed commands.
First, remove the space before the file name.
The second will add the rest to complete the link.
The xargs command is used with echo and print the first part of the link.
Finally, we use <<< aaaa.html to output the HTML file.
And this is the final command:
1 2 3 | f1='<img src="image/';ll | awk '/jpg/ {print $9}' | xargs -n1 echo $f1 | sed 's/\/ /\//g' | sed 's/jpg/jpg\" alt=\"\" \/\>/g' |
This is all.