LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-23-2005, 10:52 AM   #1
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Rep: Reputation: 79
working on files with sed and pipe


Hello every one.

I try to do some thing with sed and | redirection i know it's possible but couldn't manage to done it.

Here is the problem:

I have 1 file template.htm whith a variable "XXX" in it. The file look like this:

Code:
<html>
<head>
<title>Download XXX on this page.</title>
</head>
<body>
bla bla XXX.zip
</body>
</html>
and a list of file in a test file let say list.txt this file look like this:
Code:
File1.zip.htm
File2.zip.htm
File3.zip.htm
and i'm looking for a command line to copie the file template.htm to each name file in list.txt File1.zip.htm, File2.zip.htm, etc... and replace the variable "XXX" by the name of the file without the extention .zip.html
so the File1.zip.htm would look like this:

Code:
<html>
<head>
<title>Download File1 on this page.</title>
</head>
<body>
bla bla File1.zip
</body>
</html>
I've try alot of thing with cat and sed command but no clue.
any lead would by very appreciate.

Thanks
 
Old 10-23-2005, 11:32 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
This problem is just begging to use a HERE document.

Take a file named "filelist":
Code:
File1.zip.htm
File2.zip.htm
File3.zip.htm
And a bash script that contains your template in a HERE document:
Code:
#!/bin/bash
for file in $( cat filelist ); do
   cat >get${file%.zip.htm}.htm << EOF
<html>
<head>
<title>Download ${file%.zip.htm} on this page.</title>
</head>
<body>
bla bla ${file%.htm}
</body>
</html>
EOF
done
Because you chose filenames that didn't contain whitespace or meta characters,
I didn't have to change the IFS variable or double quote the variables.

Last edited by jschiwal; 10-23-2005 at 12:34 PM.
 
1 members found this post helpful.
Old 10-23-2005, 12:06 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Correction. My example Needs fixing!!!

Ignore this message. First post was fixed.

Last edited by jschiwal; 10-23-2005 at 12:35 PM.
 
Old 10-23-2005, 02:07 PM   #4
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Original Poster
Rep: Reputation: 79
Re: Correction. My example Needs fixing!!!

Quote:
Originally posted by jschiwal
Ignore this message. First post was fixed.
Hello jschiwal

Thanks a million.

Just a quick modification...

Code:
#!/bin/bash
for file in $( cat filelist ); do
   cat >${file%.zip.htm}.htm << EOF
<html>
<head>
<title>Download ${file%.zip.htm} on this page.</title>
</head>
<body>
bla bla ${file%.htm}
</body>
</html>
EOF
done
I think it's better like this (i just remove the get after cat >) odevice you get an output for files name like getfile1.htm


Thanks again for this script, i was working on it sinse the beginning of this weekend.
so now i create a bite more than 1500 file in 20s using this script

Last edited by angel115; 08-12-2006 at 08:57 AM.
 
Old 10-23-2005, 06:15 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The script was just a sample. Those were the files that I created when testing it out, so I assume yours will be different. I'm sure the final script won't use "bla bla" either!

I had mistakenly changed the name of the variable from file to flist for some stupid reason, and it took about 6 edits to find and correct the mistake.

Last edited by jschiwal; 10-23-2005 at 06:17 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pipe inside variable isn't working in bash Reginald0 Linux - General 6 12-09-2015 09:56 AM
Transphering files over a remote named pipe breik Linux - Networking 1 10-02-2005 01:10 PM
Using sed on several files at once davholla Linux - General 12 04-03-2005 07:47 AM
bash: cp files and sed nachtfalter Programming 3 10-04-2004 07:06 PM
cannot delete certain files with sed ganninu Linux - General 6 12-10-2003 03:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration