[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..
# 8  
Old 08-19-2010
Well the paths are like this:
/home/$USER/Pictures/Nice\ Pictures/bla.jpg

I mean that have a backslash before every space.
:/
# 9  
Old 08-19-2010
You can give this a try:
Code:
awk '{gsub("\\\ ","#");print}' file| awk '/^\/home\/.*.(jpg|png)/{gsub("#"," ");print}' RS=" " > newfile

# 10  
Old 08-19-2010
Quote:
Originally Posted by Franklin52
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
Your solution doesn't seem to work at all...
Code:
alex@MaD-pc:~$ cat test
/home/my.jpg /home/me and you.png Hello all.jpg This is a file And another file /home/a file.txt
alex@MaD-pc:~$ cat test2

alex@MaD-pc:~$ awk '/^\/home\/.*.(jpg|png)/' RS=" " test > test2
alex@MaD-pc:~$ cat test2
/home/my.jpg
alex@MaD-pc:~$

# 11  
Old 08-19-2010
Quote:
Originally Posted by hakermania
Well the paths are like this:
/home/$USER/Pictures/Nice\ Pictures/bla.jpg

I mean that have a backslash before every space.
:/
Then the line in your file should be like:
Code:
/home/my.jpg /home/me\ and\ you.png Hello\ all.jpg This\ is\ a\ file And\ another\ file /home/a\ file.txt

# 12  
Old 08-19-2010
Quote:
Originally Posted by Franklin52
You can give this a try:
Code:
awk '{gsub("\\\ ","#");print}' file| awk '/^\/home\/.*.(jpg|png)/{gsub("#"," ");print}' RS=" " > newfile

This shows a warning
Code:
awk: warning: escape sequence `\ ' treated as plain ` '

and then does nothing.....Just copies the contents of file to newfile

---------- Post updated at 10:04 AM ---------- Previous update was at 08:29 AM ----------

Anyway. I found a solution....
In the C++ program, for them who know QtCreator, i had a QStringLIst and I did join("\n")
instead of join(" ") and the problem was solved. Thx anyway!
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