swaping of first 2 words in every line using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting swaping of first 2 words in every line using sed
# 1  
Old 05-28-2008
swaping of first 2 words in every line using sed

Please any one can help me how to swap first 2 words in every line in a file using sed

Thankk you
# 2  
Old 05-28-2008
Hammer & Screwdriver

One more homework question coming...Smilie

What did you try...??
# 3  
Old 05-28-2008
Quote:
Originally Posted by web123
Please any one can help me how to swap first 2 words in every line in a file using sed

Thankk you
I tried

sed 's/(^\([^]\)\([^]\)/ \2 \1/' {filename}

but it didn't worked
# 4  
Old 05-28-2008
Quote:
Originally Posted by web123
I tried

sed 's/(^\([^]\)\([^]\)/ \2 \1/' {filename}

but it didn't worked
Use:
Code:
sed -e "s/\([^ ]*\) *\([^ ]*\)/\2 \1 /g" file

# 5  
Old 05-28-2008
Quote:
Originally Posted by web123
Please any one can help me how to swap first 2 words in every line in a file using sed

Thankk you
Thankyou mate
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 multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 Replies

3. Shell Programming and Scripting

USING sed to remove multiple strings/words from a line

Hi I use sed comnand to remove occurance of one workd from a line. However I need to removed occurance of dufferent words in ne line. Original-1 Hi this is the END of my begining Comand sed s/"END"/"start"/g Output-1 Hi this is the start of my beginig But I have more... (9 Replies)
Discussion started by: mnassiri
9 Replies

4. Shell Programming and Scripting

SED - delete words between two possible words

Hi all, I want to make an script using sed that removes everything between 'begin' (including the line that has it) and 'end1' or 'end2', not removing this line. Let me paste an 2 examples: anything before any string begin few lines of content end1 anything after anything before any... (4 Replies)
Discussion started by: meuser
4 Replies

5. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

6. Shell Programming and Scripting

How to print the words in the same line with space or to the predefined line?

HI, cat test abc echo "def" >> test output is cat test abc def the needed output is cat test abc def and so on (5 Replies)
Discussion started by: jobycxa
5 Replies

7. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

8. Shell Programming and Scripting

swaping sections of lines

Is it possible to do this with sed? Go from this: 958211 XXYYXXYYXX file1 file2 file3 958897 XXYYXXYYXX file1 file2 To this: file1 file2 file3 XXYYXXYYXX 958211 file1 file2 XXYYXXYYXX 958897 The only thing consistant is XXYYXXYYXX. The numbers and files vary in length. I have seen I... (5 Replies)
Discussion started by: crowman
5 Replies

9. Shell Programming and Scripting

swap words in a line with sed

Hello. There is something I can not manage : I want to swap the first word with the third one in every line. No file is given the input is read from the keyboard. I know I have to use sed, but it seems this is too complicated for me. Could you help me please ? Thanks, atticus (9 Replies)
Discussion started by: atticus
9 Replies

10. UNIX for Dummies Questions & Answers

Number Swaping.... in file

I have a file having entries like 1270 (about 55000 entries like this). i want to swap these numbers like 2107... Any Idea (3 Replies)
Discussion started by: muneebr
3 Replies
Login or Register to Ask a Question