Chris February 2016

Add URL to lines in specific file

I am trying to add a URL to individual lines in a list downloaded using wget.

The first portion of the Bash script below downloads the list and the URL is static. The sed command was an attempt to add the URL to the list.

bash

#!/bin/bash
wget -q --user=xxxx --password=xxxxx --xxxx \
xxx://www.xxx.com/xxxx/xxx/xxxx/list

url=xxx://www.xxx.com/xxxx/xxx/xxxx/

sed s/$url/ list.txt | url_list.txt
sed: -e expression #1, char 14: unknown option to `s'

current list

FilterDuplicates.html
file1.bam
file2.bam
file1.vcf.gz
file2.vcf.gz

desired list (with the $url before the filename)

xxx://www.xxx.com/xxxx/xxx/xxxx/FilterDuplicates.html
xxx://www.xxx.com/xxxx/xxx/xxxx/file1.bam
xxx://www.xxx.com/xxxx/xxx/xxxx/file2.bam
xxx://www.xxx.com/xxxx/xxx/xxxx/file1.vcf.gz
xxx://www.xxx.com/xxxx/xxx/xxxx/file2.vcf.gz

edit

#!/bin/bash
 wget -q --user=xxxx --password=xxxx --xxxx \
 https://www.xxxx.com/xxx/xx/xxxx/file

 $url="https://www.xxxx.com/xxx/xx/xxxx/";
 sed "s|^|$url|" /home/cmccabe/list > /home/cmccabe/url_list.txt
 https://www.xxxx.com/xxx/xx/xxxx/: no such file or directory

This is sed is close but it appends the url to the end of the file, not to each line like the desired output. Thank you :)

sed -i '$a https://www.xxxx.com/xxx/xx/xxxx/' /home/cmccabe/list

output

FilterDuplicates.html
file1.bam
file2.bam
file1.vcf.gz
file2.vcf.gz
https://www.xxxx.com/xxx/xx/xxxx/

sed command to add text

sed 's/^/https://www.xxxx.com/xxx/xx/xxxx//' /home/cmccabe/list

Answers


karakfa February 2016

pick a separator char (here pipe) not part of your url string.

sed 's|^|http://example.com/|' file

or if you have the url as a variable, easiest will be using double quotes instead.

$ url="http://example.com/"; sed "s|^|$url|" file

Post Status

Asked in February 2016
Viewed 1,754 times
Voted 5
Answered 1 times

Search




Leave an answer