REGEX to separate paths by whitespace and do a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting REGEX to separate paths by whitespace and do a loop
# 1  
Old 12-01-2015
REGEX to separate paths by whitespace and do a loop

I am trying to do in a single line to take a list of paths separated by whitespace and then loop thru all the paths that were wrote but my regex is not working,

I have

Code:
echo {3} | sed 's/ //g' | while read EACHFILE
do
 .....

But for some reason is only taking always the first path that I have in the line as I mention it below

Code:
hpsvn mergebatch E1 Homepage uk/rwd/heroes/40034/hero.html uk/rwd/heroes/40035/hero.html

So with this regex it is only taking the first uk/rwd/heroes/40034/hero.html but never getting the 2nd or 3rd one. Any ideas?
# 2  
Old 12-01-2015
Quote:
Originally Posted by jorgejac
I am trying to do in a single line to take a list of paths separated by whitespace and then loop thru all the paths that were wrote but my regex is not working,

I have

Code:
echo {3} | sed 's/ //g' | while read EACHFILE
do
 .....

But for some reason is only taking always the first path that I have in the line as I mention it below

Code:
hpsvn mergebatch E1 Homepage uk/rwd/heroes/40034/hero.html uk/rwd/heroes/40035/hero.html

So with this regex it is only taking the first uk/rwd/heroes/40034/hero.html but never getting the 2nd or 3rd one. Any ideas?
I'm lost. The command echo {3} will send {3} as a single line to sed, the sed command (finding no spaces to remove) will send {3} to your while loop using read to set EACHFILE to {3} the first (and only) time through the loop. No pathnames (or filenames) have been passed to your loop in any way by this code???
  1. Is this a homework assignment?
  2. Where the names of the files you want to process are coming from?
  3. What operating system you're using?
  4. What shell you're using?
  5. Are you saying that the files you want to process have names that contain whitespace characters?
# 3  
Old 12-02-2015
I am doing a custom svn merge function that will take the parameters the path of all the files that are wanted to be merged

Code:
hpsvn mergebatch E1 Homepage uk/rwd/heroes/40034/hero.html uk/rwd/heroes/40035/hero.html

so in the function, I am trying to do that my custom svn command will take a list of paths separated by space, then inside my function, in the while, I am separating by / to take the subdirectory and do the svn add and svn merge for each file. Currently my code is working but only for one path, but it is not taking the 2nd one.

Let me know if this was clear.
# 4  
Old 12-02-2015
It is not clear.

In post #3, I asked 5 questions. I think you have now said that the answer to #5 is no.

Please answer the other 4 questions:
  1. Is this a homework assignment?
  2. What command, function, ... is used to create the list of pathnames you want to process?
  3. What operating system are you using?
  4. What shell are you using?
so we can make suggestions that might help you resolve your problem!
# 5  
Old 12-02-2015
Is this a homework assignment? WORK ASSIGNMENT
What command, function, ... is used to create the list of pathnames you want to process? the paths are typed manually, pointing to the file that is in the webserver
What operating system are you using? shell, putty, unix
What shell are you using? putty
# 6  
Old 12-02-2015
I'm still struggling with your request. Please give us a sample of "a list of paths separated by whitespace". If I presume such a list, your sed 's/ //g' will make it one single long string of no use in a for loop. And, "paths are typed manually, pointing to the file that is in the webserver" is beyond my imagination. Please give us samples of your input data and some rudimentary code snippet that is supposed to work on it.

And, "putty" is not a shell but a communication tool. Shells might be sth. like sh, ksh, bash, (csh, tcsh)
# 7  
Old 12-02-2015
If you're typing the paths in manually, just change:
Code:
echo {3} | sed 's/ //g' | while read EACHFILE
do
 .....

to:
Code:
printf '%s\n' hpsvn merge batch E1 Homepage uk/rwd/heroes/40034/hero.html uk/rwd/heroes/40035/hero.html | while read EACHFILE
do
 .....

or:
Code:
for EACHFILE in hpsvn mergebatch E1 Homepage uk/rwd/heroes/40034/hero.html uk/rwd/heroes/40035/hero.html
do
 .....

But, of course, all of this is assuming that you are using a shell that uses basic Bourne shell syntax. (As RudiC said, putty is not a shel. And shell, putty, unix is not an operating system.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Change name of files to their paths -- find loop

Dear All, I have many sub-folders but each of them have a file with same name but different data. I want to either move or copy them into a new folder but they need to have the path of where they are coming as part of their name... I have managed to find the files but dont know how to change... (2 Replies)
Discussion started by: A-V
2 Replies

2. Shell Programming and Scripting

Separate by more than whitespace.

This is my file .........hostname.............this is hostname .........alias...................alias name Remark use dot(.) instead of whitespace B'cuz this forum not allow to use more whitespace. --------------------------------------- I sperate by whitespace not work. awk 'BEGIN {FS=" "}... (4 Replies)
Discussion started by: cyberking
4 Replies

3. Shell Programming and Scripting

loop through lines and save into separate files

I have two files: file-gene_families.txt that contains 30,000 rows of 30 columns. Column 1 is the ID column and contains the Col1 Col2 Col3 ... One gene-encoded CBPs ABC 111 ... One gene-encoded CBPs ABC 222 ... One gene-encoded CBPs ABC 212 ... Two gene encoded CBPs EFC... (7 Replies)
Discussion started by: yifangt
7 Replies

4. UNIX for Dummies Questions & Answers

awk to match multiple regex and create separate output files

Howdy Folks, I have a list that looks like this: (file2.txt) AAA BBB CCC DDD and there are 24 of these short words. I am matching these patterns to another file with 755795 lines (file1.txt). I have this code for matching: awk -v f2=file2.txt ' BEGIN { while(... (2 Replies)
Discussion started by: heecha
2 Replies

5. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

6. Solaris

SAN - Hard loop / prefered paths - help

Hi all Right, Im a little bit thick when it comes to SAN :-) IVe got a dual port qlc in a solaris 10 server. Its all connected and I can see a number of disks. The SAN guy here has asked me about preferred paths, i.e. as the dual ports are connected to two fabrics, etc device will have 4... (2 Replies)
Discussion started by: sbk1972
2 Replies

7. Shell Programming and Scripting

Preventing whitespace to be a delimiter in a for loop (bash/sh)

Hi, I have a for loop which iterates over a list of strings, separated by whitespace: $ list="1 2 3" $ for i in $list; do echo $i; done 1 2 3 I now want to introduce some strings containing whitespace themselves ... This is straightforward if I directly iterate over the list: $ for... (4 Replies)
Discussion started by: kkkoehne
4 Replies

8. Shell Programming and Scripting

Whitespace in filenames in for loop in bash script

I'm trying to search all .odt files in a directory for a string in the text of the file. I've found a bash script that works, except that it can't handle whitespace in the filenames. #!/bin/bash if ; then echo "Usage: searchodt searchterm" exit 1 fi for file in $(ls *.odt); do ... (4 Replies)
Discussion started by: triplemaya
4 Replies

9. Shell Programming and Scripting

Preserving whitespace in a for loop

I obviously haven't learned my lesson with shell and whitespace. find /path/to/some/where/ -name "*.pdf" | awk '{print $5}'| uniq -d results: some Corporation other Corporate junk firmx Works fine from cmdline but the whitespace turns into another FS in a for loop. for... (7 Replies)
Discussion started by: s_becker
7 Replies

10. Shell Programming and Scripting

while read loop preserving leading whitespace

Hi all, I've been trying to get this to work for ages to no avail. I've searched this site and googled but cannot find a satisfactory answer. I've got a while loop, like this while read line do echo "$line" done < file_name Now, my problem is that most of the lines in the file... (3 Replies)
Discussion started by: zazzybob
3 Replies
Login or Register to Ask a Question