How to move a group of words before another group of words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to move a group of words before another group of words
# 1  
Old 12-29-2011
How to move a group of words before another group of words

Hi

I have a file containing lines with several consecutive words starting with a capital letter (i.e. Zuvaia Flex), followed by "de The New Foul", and I would like to put "The New Foul" before the group with capital letters and delete "de"
From the line:
Code:
    Le short femme Zuvaia Flex de The New Foul se distingue par


I need to obtain:
Code:
    Le short femme The New Foul Zuvaia Flex se distingue par


Another example of a line to search and replace:
le molleton Bise Chop Durel - XS de
The New Foul. Composé de roustane avec barrettes de renflex

For now I have come up with a sed oneliner:
Code:
 sed 's/\( [a-z]* \)\(([A-Z][a-z]* )*\)[^A-Z ]*de \(The North Face\)/\1\3 \2/g' target.txt > done.txt 



but it does not work.
Can you help me?

Thank you

Last edited by louisJ; 12-29-2011 at 08:09 AM..
# 2  
Old 12-29-2011
Hi,
Why don't you try simple search & replace.
Code:
 sed 's/Zuvaia Flex de The New Foul/The New Foul Zuvaia Flex/' filenmae

# 3  
Old 12-29-2011
Code:
# cat infile
Le short femme Zuvaia Flex de The New Foul se distingue par
Le molleton Bise Chop Durel - XS de The New Foul. Composé de roustane avec barrettes de renflex

Code:
# perl -lne '/(^.*?[a-z]\w+\s)([A-Z].*)\sde\s(?=(The New Foul)(.*))/;print $1.$3." ".$2.$4' infile          
Le short femme The New Foul Zuvaia Flex se distingue par
Le molleton The New Foul Bise Chop Durel - XS. Composé de roustane avec barrettes de renflex

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

Search words in any quote position and then change the words

hi, i need to replace all words in any quote position and then need to change the words inside the file thousand of raw. textfile data : "Ninguno","Confirma","JuicioABC" "JuicioCOMP","Recurso","JuicioABC" "JuicioDELL","Nulidad","Nosino" "Solidade","JuicioEUR","Segundo" need... (1 Reply)
Discussion started by: benjietambling
1 Replies

3. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

4. Shell Programming and Scripting

Gawk gensub, match capital words and lowercase words

Hi I have strings like these : Vengeance mitt Men Vengeance gloves Women Quatro Windstopper Etip gloves Quatro Windstopper Etip gloves Girls Thermobite hooded jacket Thermobite Triclimate snow jacket Boys Thermobite Triclimate snow jacket and I would like to get the lower case words at... (2 Replies)
Discussion started by: louisJ
2 Replies

5. Shell Programming and Scripting

How count the number of two words associated with the two words occurring in the file?

Hi , I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying: grep "error" log.txt | wc -l (1 Reply)
Discussion started by: jmarx
1 Replies

6. Shell Programming and Scripting

Get group of consecutive uppercase words using gawk

Hi I'd like to extract, from a text file, the strings starting with "The Thing" and only composed of words with a capital first letter and apostrophes, like for example: "The Thing I Only" from "those are the The Thing I Only go for whatever." or "The Thing That Are Like Men's Eyewear" ... (7 Replies)
Discussion started by: louisJ
7 Replies

7. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

8. Shell Programming and Scripting

matching group of words

Hi, I am stuck with a problem, will be thankful for your guidance and help. I have two files. Each line is a group of words with first word as group Id. eg. 'gp1' in File1 and 'grp1' in File2. <File1> gp1 : xyz xys3 syt2 ssx itt kty gp2 : syt2 kgk iti op2 gp3 : ppy yt5 itt sky... (11 Replies)
Discussion started by: mira
11 Replies

9. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

10. Solaris

Solaris + VCS , move a resource to another group

Hi, I am running Solaris 10 + VCS 5 in one of our environment. Recently one of my colleague configured all resources in a single service group.( ie, one service group which has all resources) ,Usually we create seperate service groups for Hardware & for application. For eg: SYS_HW_GRP, will... (0 Replies)
Discussion started by: mpics66
0 Replies
Login or Register to Ask a Question