Cutting text from one location to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting text from one location to another
# 8  
Old 11-29-2006
Error

Quote:
Originally Posted by hemangjani
The following text appears multiple times in a script and it resides in many scripts.
I would like to make the following changes to the text:

Text:
/usr/local/bin/gmail -t abc@yahoo.com -m "this is a test" -f xyz@yahoo.com

I need to cut the text that comes after -m which is "this is a test" and place it in front of the line with echo statment.
I think Awk will not work as -m will not be in the same column everytime.

final result:

echo "this is a test" | /usr/local/bin/gmail -t abc@yahoo.com -m -f xyz@yahoo.com

Any suggestions?

Thank you.


thans self
# 9  
Old 11-29-2006
Thank you Glenn, Matrix and Aju for the help.

Seems like I am moving forward. Below is Input files, Code and Output on screen.
Now, how would I replace the current line with the edited line (temp1 in my code)?

Thanks again everyone for the input. I'm learning new things here.
--------------------------

Input file 1:

this is line 1 of test file
this is line 2 of test file
/usr/local/bin/gmail -s "Subject line" abc@yahoo.com lmn@yahoo.com -m " Message for file 1 " -f xyz@yahoo.com -a /home/kcc1hxj/testfile1.txt
this is line 4 of test file

Input file 2:

this is line 1 of test file
this is line 2 of test file
/usr/local/bin/gmail -s "Subject line" -a /home/kcc1hxj/testfile2.txt abc@yahoo.com lmn@yahoo.com -m " Message for file 1 " -f xyz@yahoo.com
this is line 4 of test file

Code:

#!/bin/ksh
for file in /home/kcc1hxj/projects/removemail/scripts/*
do
temp1=`grep ^.*/usr/local/bin/gmail $file | sed 's/\(.*-m \)\(".*"\)\( .*\)/echo \"\2\" | \1\3/' | sed 's/""/"/g'`
echo $temp1
done

Output on screen:

echo " Message for file 1 " | /usr/local/bin/gmail -s "Subject line" abc@yahoo.com lmn@yahoo.com -m -f xyz@yahoo.com -a /home/kcc1hxj/testfile1.txt
echo " Message for file 1 " | /usr/local/bin/gmail -s "Subject line" -a /home/kcc1hxj/testfile2.txt abc@yahoo.com lmn@yahoo.com -m -f xyz@yahoo.com


Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find a existing file location and directory location in Solaris box?

Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box (1 Reply)
Discussion started by: buzzme
1 Replies

2. 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

3. Shell Programming and Scripting

cutting long text by special char around 100 byte and newline

Regard, How can i cut the text by special char(|) around 100 byte and write the other of the text at newline using Perl. ... (3 Replies)
Discussion started by: Shawn, Lee
3 Replies

4. Shell Programming and Scripting

File created in a different location instead of desired location on using crontab

Hi, I am logging to a linux server through a user "user1" in /home directory. There is a script in a directory in 'root' for which all permissions are available including the directory. This script when executed creates a file in the directory. When the script is added to crontab, on... (1 Reply)
Discussion started by: archana.n
1 Replies

5. Shell Programming and Scripting

Cutting out text from specific portion on filename

Hi, how do I go about cutting out the first numeric characters after the word "access"? access1005101228.merged-00.15.17.86.d8.b8.log.gz (16 Replies)
Discussion started by: GermanJulian
16 Replies

6. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

7. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

8. UNIX for Advanced & Expert Users

copy files from one location to similar location

I need help in forming a script to copy files from one location which has a sub directory structure to another location with similar sub directory structure, say location 1, /home/rick/tmp_files/1-12/00-25/ here 1-12 are the number of sub directories under tmp_files and 00-25 are sub... (1 Reply)
Discussion started by: pharos467
1 Replies

9. HP-UX

replacing text in specific location

i have a file that looks like this: 000000112/01/2008 D99999 000000 12/01/2008 D99999 000000 12/01/2008 1D99999 i need to replace the blanks into 1 for column 7,18-19 how can this be achieved using awk? Thanks. (1 Reply)
Discussion started by: zeontman
1 Replies

10. Shell Programming and Scripting

cutting unwanted text

Hello, I have a log file which looks like this : I want to cut out some text and get printed only : "HTTP GET" and "Time duration: 1013 mls. (1 sec.)" I tried searching the forum for such solution, but I was unable to find it. I also tried awk '/duration/ { print $0 }' mylogfile.log,... (2 Replies)
Discussion started by: sysgate
2 Replies
Login or Register to Ask a Question