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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying x words from end of line to specific location in same line
# 8  
Old 02-18-2010
Quote:
Originally Posted by princesasa
[...]
and i really want to learn this language
what is the best way to learn it ?
Visit www.unix.com more frequently.
# 9  
Old 02-19-2010
Hello
now i had little problem

the input is :
Code:
Redirect 303 /up/upfiles/zst29595.jpg /http://img682.imageshack.us/img682/4786/zst29595.jpg
Redirect 303 /up/upfiles/ztj10579.jpg /http://img404.imageshack.us/img404/9339/ztj10579.jpg

notice the / before http

the output should be :
Code:
Redirect 303 /up/upfiles/zst29595.jpg http://img682.imageshack.us/img682/4786/zst29595.jpg
Redirect 303 /up/upfiles/ztj10579.jpg http://img404.imageshack.us/img404/9339/ztj10579.jpg

Thanks in advance

Last edited by princesasa; 02-19-2010 at 08:38 PM..
# 10  
Old 02-19-2010
Code:
$ 
$ cat f4
Redirect 303 /up/upfiles/zst29595.jpg /http://img682.imageshack.us/img682/4786/zst29595.jpg
Redirect 303 /up/upfiles/ztj10579.jpg /http://img404.imageshack.us/img404/9339/ztj10579.jpg
$ 
$ # Using sed
$ sed 's/\/http/http/' f4
Redirect 303 /up/upfiles/zst29595.jpg http://img682.imageshack.us/img682/4786/zst29595.jpg
Redirect 303 /up/upfiles/ztj10579.jpg http://img404.imageshack.us/img404/9339/ztj10579.jpg
$ 
$ # Using awk
$ awk 'sub("/http","http")' f4
Redirect 303 /up/upfiles/zst29595.jpg http://img682.imageshack.us/img682/4786/zst29595.jpg
Redirect 303 /up/upfiles/ztj10579.jpg http://img404.imageshack.us/img404/9339/ztj10579.jpg
$ 
$ # Using Perl
$ perl -lne 's/\/http/http/; print' f4
Redirect 303 /up/upfiles/zst29595.jpg http://img682.imageshack.us/img682/4786/zst29595.jpg
Redirect 303 /up/upfiles/ztj10579.jpg http://img404.imageshack.us/img404/9339/ztj10579.jpg
$ 
$ # Using Ruby
$ ruby -pe 'sub("/http","http")' f4
Redirect 303 /up/upfiles/zst29595.jpg http://img682.imageshack.us/img682/4786/zst29595.jpg
Redirect 303 /up/upfiles/ztj10579.jpg http://img404.imageshack.us/img404/9339/ztj10579.jpg
$ 
$

tyler_durden
# 11  
Old 02-20-2010
Hello
Extremely wonderful tyler
you made me really speechless
thanks a loot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert character at specific location in a each line of the file

Hi All, I am trying to write a shell script where it should insert character 'I' in 180th position of each line(except first and last line) of the file. Below is the script for file in /home/test/bharat/*.RET do # Process file echo "File Name=" $file #l_fileName="${file##*/}" ... (19 Replies)
Discussion started by: bharath561989
19 Replies

2. Shell Programming and Scripting

Bash: copying lines with specific character to files with same name as copied line.

I am trying to make my script as simple as a possible but, I am not sure if the way I am approaching is necessarily the most efficient or effective it can be. What I am mainly trying to fix is a for loop to remove a string from the specified files and within this loop I am trying to copy the lines... (2 Replies)
Discussion started by: Allie_gastrator
2 Replies

3. UNIX for Dummies Questions & Answers

How to return only specific words in a line?

Hi, I'm a bash newbie and have a data set like this idxxx1 something something marker_id_132=rsxxx;marker_id_135=rsxxx idxxx2 something something marker_id_132=rsxxx;marker_id_135=rsxxx idxxx3 something something marker_id_132=rsxxx;marker_id_135=rsxxx ... ... (7 Replies)
Discussion started by: hanhel
7 Replies

4. Shell Programming and Scripting

Insert text line to specific location CSV

In Perl. ***edited question below*** Hey all, I am teaching myself some simple CSV file manipulation and have become a little stuck. Say I have the following layout in the CSV file: age,name,locationIs it possible to INSERT data into the CSV into the correct age order. For example, if I had... (1 Reply)
Discussion started by: whyte_rhyno
1 Replies

5. Shell Programming and Scripting

Interchange location of words in a line of csv file

Hi, I have a file with some info as example below. Its a csv file and i want to interchange the location of the times and dates in the 3rd and 4th fields only. I am using SunOS and csh script and would like to incorporate sed or nawk in the script (or any that would be able to accomplish this).... (5 Replies)
Discussion started by: viper1503
5 Replies

6. Shell Programming and Scripting

copying to the end of the line

Hi, I have a file as such 1 <text1><text2></ 2 <text3><text4></ 3 <text5><text6></ 4 <text7><text8></ I need is so the first bit of text in the line is at the end as its xml so 1 <text1><text2></text1> 2 <text3><text4></text3> 3 <text5><text6></text5> 4 ... (12 Replies)
Discussion started by: legolad
12 Replies

7. Shell Programming and Scripting

Extract X words from end of line, minus last keynumber X

The file contains one line of text followed by a number. I want to take the number X at the end, take it out and display the last X words. X is the key telling me how many words from the end that I want and X will always be less than the number of words, so no problem there. Example input and... (4 Replies)
Discussion started by: fubaya
4 Replies

8. Shell Programming and Scripting

How to append a string to a specific location in a line

Hi, I have a to modify a line and insert a keyword in the middle to a specific location. My line looks like this FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS (ABC, DEF, GHI) I want to change it as FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING... (4 Replies)
Discussion started by: mwrg
4 Replies

9. Shell Programming and Scripting

how to Add word at specific location in line

eg . i have file x.txt contains : java coding , shell scriptting etc... now i want to add "is langauge" after word java. output should be java is langauge coding , shell scriptting etc... any idea how to use shell script to do it ? (10 Replies)
Discussion started by: crackthehit007
10 Replies

10. Shell Programming and Scripting

How to append words at the end of first line

Hi Unix gurus This is my first post here. I have a file which looks like this: string1,string2 ,string3 ,string4 ... ... I need to append all words below first line to the first line, ie string1,string2,string3,string4,... Bear in mind that it is not known how many lines follow... (11 Replies)
Discussion started by: lmatlebyane
11 Replies
Login or Register to Ask a Question