[Solved] Read a line from one string till to another.... Unix scripting..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Read a line from one string till to another.... Unix scripting..
# 1  
Old 08-19-2010
Tools [Solved] Read a line from one string till to another.... Unix scripting..

So i have a file which contains paths to JPG images separated by a space.
I have to separate them each path to another file. So, I have to search all strings that start from /home/ and ends with .jpg or .png
Then write each one to another file...

Can you please help me on doing this???Smilie
# 2  
Old 08-19-2010
One way:
Code:
awk '/^\/home\/.*.jpg/ || /^\/home\/.*.png/' file > newfile

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 08-19-2010
Without sample data it is hard to produce anything... but try this:
Code:
cat file1 | tr " " "\n" | awk '/^\/home\/.+\.(jpg)|(png)/' > file2

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 08-19-2010
Thanks for your replies. Bartus11's solution is more useful. It writes every path to a file separated by endline
Cool Smilie

---------- Post updated at 06:51 AM ---------- Previous update was at 06:38 AM ----------

Another problem was created. Some Dirs have spaces (e.g. Hello all), and i have made another script that in every (space)a-z,A-Z convert it to \(space)a-z,A-Z

Unfortunately, both of your solutions don't work correctly in case one of the image's paths does have spaces.. :/
# 5  
Old 08-19-2010
Quote:
Originally Posted by hakermania
Thanks for your replies. Bartus11's solution is more useful. It writes every path to a file separated by endline
Cool Smilie
In that case you can try this without cat and tr:
Code:
awk '/^\/home\/.*.(jpg|png)/' RS=" " file > newfile

# 6  
Old 08-19-2010
Franklin52 --> Now the problem is other. Read my last post for details
# 7  
Old 08-19-2010
Quote:
Originally Posted by hakermania
Franklin52 --> Now the problem is other. Read my last post for details
If you have a lines like:
Code:
/home/my.jpg /home/me and you.png Hello all.jpg This is a file And another file /home/a file.txt

then you don't have another problem but a serious problem IMHO Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

2. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

3. Shell Programming and Scripting

Html parsing - get line after specific string till a point

Hi all :) It sounds complex, for example I want to find the whole html file (there are 5 entries of this string and I need to get all of them) for the string "<td class="contentheading" width="100%">", get the next line from it only till the point that says "</td>", plus removing \t (tabs) ... (6 Replies)
Discussion started by: hakermania
6 Replies

4. Shell Programming and Scripting

[Solved] Read a .gz file line by line without using gzcat

Hi all Is there a way to read and process a gzip file line by line similar to a text file without using gzcat.. while processing a text file we will usually use the logic exec<sample.txt while read line do echo $line done Is there a similar way to process the gz file in the same... (4 Replies)
Discussion started by: aikhaman
4 Replies

5. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

6. UNIX for Dummies Questions & Answers

Loop till you find a string in a fine <-- Need Help New to Unix Scripting

Guys - I am new to Unix scripting and am in need for a script that does the following. I have bits and pieces created and tested but i am just having a little difficult time getting it all together. - Loop through till it finds a string in a specific file. Any help is greatly appreciated. ... (1 Reply)
Discussion started by: mrehman
1 Replies

7. UNIX for Dummies Questions & Answers

Read lines till a blank line is encountered

Hi, I have reached at a specified offset from the start of file. My requirement is that I want to read only those lines, which have the string READ / ALTER / UPDATE. As soon as, none of these literals are found in the subsequent line, I want to stop reading. Is there any feature of grep which... (1 Reply)
Discussion started by: saurabhsinha23
1 Replies

8. UNIX for Dummies Questions & Answers

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS: SINGCORP invalid... (1 Reply)
Discussion started by: adityam
1 Replies

9. Shell Programming and Scripting

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS: SINGCORP invalid... (1 Reply)
Discussion started by: adityam
1 Replies

10. Post Here to Contact Site Administrators and Moderators

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS:... (0 Replies)
Discussion started by: adityam
0 Replies
Login or Register to Ask a Question