Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Insert folder name in text string Post 302967238 by enginama on Sunday 21st of February 2016 03:49:59 PM
Old 02-21-2016
Awesome. So put into shell script and added for loop.
Seems to work on 2 files I tested it on, so looking promising.
Thanks to everyone for all their help.

Code:
#!/bin/bash
for file in *.html;
do
sed 's#\(img src=\)"\(.*\.[jpg][pin][gf]\)"#\1"./images/\2"#g' $file > "$file.tmp" && mv "$file.tmp" "$file"
done

haven't tested it yet with png file types, but it did replace all code lines when it was a gif or jpg, so will do a final test with pngs shortly.

---------- Post updated at 02:49 PM ---------- Previous update was at 02:08 PM ----------

Definitely worked for images, now have to do the same for all the pdf files.
But below code doesn't seem to do what I need, any advice please?

Code:
for file in *.html;
do
sed 's#\(a href=\)"\(.*\.[pdf]\)"#\1"./pdfs/\2"#g' $file > "$file.tmp" && mv "$file.tmp" "$file"
done


Last edited by enginama; 02-21-2016 at 06:49 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies

2. Shell Programming and Scripting

String in text matches folder name

Hi, I need unix shell script that can read the first column of a text file and matching each column string is a folder and i need to read files from the specified folder e.g Main.txt has Mike 690 Jhon 346 i need to read Mike first then open up the files in folder Mike in the same... (2 Replies)
Discussion started by: shackman66
2 Replies

3. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

4. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

5. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

6. Shell Programming and Scripting

How to insert string at particular 4th line in text file

I just want to add a particular string in text file using shell script text file format 1 columns-10 2 text=89 3 no<> 4 5 test-9876 6 size=9 string need to insert in 4th line <switch IP='158.195.2.567' port='5900' user='testc' password='asdfrp' Code='8'> After inserting the... (8 Replies)
Discussion started by: puneet.goel
8 Replies

7. UNIX for Dummies Questions & Answers

Insert Text on lines having the string word

I need help on how I can accomplish my task. I hope someone can help me since I've researching and trying to accomplish this for hours now. Basically, I need to comment-out (or insert a # sign in the beginning of the line) a line when the line has the specific word I am searching. Example I have... (3 Replies)
Discussion started by: Orbix
3 Replies

8. Shell Programming and Scripting

Insert String every n lines, resetting line counter at desired string

I need to read a text file and insert a string every n lines, but also have the line counter restart when I come across a header string. Line repeating working every 3 lines using code: sed '0~3 s/$/\nINSERT/g' < INPUT/PATH/FILE_NAME.txt > OUTPUT/PATH/FILE_NAME.txt I cannot seem to find... (1 Reply)
Discussion started by: Skonectthedots
1 Replies

9. Shell Programming and Scripting

Insert a user input string after matched string in file

i am having file like this #!/bin/bash read -p 'Username: ' uservar match='<color="red" />' text='this is only a test so please be patient <color="red" />' echo "$text" | sed "s/$match/&$uservar\g" so desireble output what i want is if user type MARIA this is only a test so please... (13 Replies)
Discussion started by: tomislav91
13 Replies

10. UNIX for Beginners Questions & Answers

Insert text after the first occurance of searched string entry in a file

My server xml file has huge data part of which i'm sharing below. I wish to add the below text held by variable "addthisline" after the closing braces i.e --> once the first </Connector> tag is found. addthisline="I need to be inserted after the comments" Thus my searchstring is... (3 Replies)
Discussion started by: mohtashims
3 Replies
latex2png(1)						      General Commands Manual						      latex2png(1)

NAME
latex2rtf - Convert a LaTeX file to a PNG image SYNTAX
latex2png [-hk] [ -H home_directory ] [ -d dots_per_inch ] [ inputfile ] DESCRIPTION
The latex2png command converts a LaTeX file into a PNG graphic. The first page is translated into an image at the specified resolution. -d dots_per_inch Used to specify the number of dots per inch for the output image. Default is 144 dpi. -h Print a short usage note -k Keep intermediate files (for debugging). -H home_dir Add home_dir to the search path for LaTeX. SEE ALSO
latex2rtf (1). For complete, current documentation, refer to the Info file latex2rtf.info, the PDF file latex2rtf.pdf or the HTML file latex2rtf.html which are made from the TeXInfo source file latex2rtf.texi. LATEX2PNG(1) User LATEX2PNG(1) NAME
latex2png - manual page for latex2png 1.1 DESCRIPTION
latex2png -- Convert a LaTeX file to a PNG image USAGE: latex2png [-d density] [-h] [-k] [-c] [-g] [-m] [-H home dir] file[.tex|.eps] The latex2png command converts a LaTeX file into a PNG image. The first page is translated into an image at the specified resolution. latex2png can also be used to convert encapsulated postscript (EPS) files to PNG images. OPTIONS: -c produce color image -d density density is the number of dots per inch to use in the created image (default 144 dpi) -g produce gray images -h help -H home_dir home_dir is a directory to be included in search path (default is directory that contains the LaTeX file). This is used to create PNG images in another directory (e.g., /tmp) and still allow LaTeX to find files that it needs to include. -k keep intermediate files (for debugging) -m produce monochrome (black and white) image (default) -v version EXAMPLES: latex2png -d 144 /tmp/file #create /tmp/file.png at 144 dpi latex2png file.eps #create file.png latex2png file.tex #create file.png via latex latex2png -H . /tmp/file #search the cwd for image files SEE ALSO
latex2png is a part of latex2rtf and has a special mode to assist in finding the baseline of a latex equation. Documentation for latex2rtf may be found in latex2rtf.info, the PDF file latex2rtf.pdf or the HTML file latex2rtf.html which are made from the TeXInfo source file latex2rtf.texi. latex2png 1.10 November 2002 LATEX2PNG(1)
All times are GMT -4. The time now is 09:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy