shell script to add input at certain location into a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to add input at certain location into a file
# 1  
Old 08-16-2011
shell script to add input at certain location into a file

Hi,

I am using Solaris 10 OS and trying to create shell script that can add input at certain location into a file.

The input that I am trying to put is new domain name
e.g
@newdomain.com

the file contains,
Code:
more test01.out
user/zzzz786@st.com/INBOX
user/zzzz@po.com/INBOX
user/zzzzaaaa/INBOX
user/zzzzry@blo.com/INBOX
user/zzzzz@syx.com/INBOX
user/zzzzzr@strex.com/INBOX
user/zzzzzz/INBOX
user/zzzzzz16@stre.com/INBOX
user/zzzzzz7@bluo.com/INBOX
user/zzzzzzz/INBOX
user/zzzzzzz@bppo.com/INBOX

output should be,
Code:
user/zzzz786@st.com/INBOX
user/zzzz@po.com/INBOX
user/zzzzaaaa@newdomain.com/INBOX
user/zzzzry@blo.com/INBOX
user/zzzzz@syx.com/INBOX
user/zzzzzr@strex.com/INBOX
user/zzzzzz@newdomain.com/INBOX
user/zzzzzz16@stre.com/INBOX
user/zzzzzz7@bluo.com/INBOX
user/zzzzzzz@newdomain.com/INBOX
user/zzzzzzz@bppo.com/INBOX

thank you for your kindly help
# 2  
Old 08-16-2011
Try (not tested I'm on windows now):
Code:
sed '/@/! s|/INBOX|@newdomain.com/INBOX|'

This User Gave Thanks to yazu For This Post:
# 3  
Old 08-16-2011
Code:
nawk -F"/" '{if($0!~/@/){print $1"/"$2"@newdomain.com/"$3}else{print $0}}' test01.out

This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 08-16-2011
tested and working just fine. thanks for your help, any tips guide to construct such code guys? man I have no idea where to start
# 5  
Old 08-16-2011
hmm... start from the basic unix commands and read about the control statements and some basic tutorials and examples.. ( just google it )
search this forum for "new to unix".. you see lot of threads and lot of suggestions from people.
https://www.unix.com/im-new-unix-book...nix-books.html
This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 08-16-2011
Quote:
Originally Posted by itkamaraj
hmm... start from the basic unix commands and read about the control statements and some basic tutorials and examples.. ( just google it )
search this forum for "new to unix".. you see lot of threads and lot of suggestions from people.
https://www.unix.com/im-new-unix-book...nix-books.html

thx for the recommendation. I will look into it asap.

anyway got another question,

how can we remove certain values in the files?
a)one by one.
b)multiple values
-need separate script

e.g base on this file structure,
Code:
more file01.out
user/zzzz786@st.com/INBOX 
user/zzzz@po.com/INBOX 
user/zzzzaaaa@newdomain.com/INBOX 
user/zzzzry@blo.com/INBOX 
user/zzzzz@syx.com/INBOX 
user/zzzzzr@strex.com/INBOX 
user/zzzzzz@newdomain.com/INBOX 
user/zzzzzz16@stre.com/INBOX 
user/zzzzzz7@bluo.com/INBOX 
user/zzzzzzz@newdomain.com/INBOX 
user/zzzzzzz@bppo.com/INBOX

e.g file after removed "user/zzzzry@blo.com/INBOX"
Code:
more file01.out
user/zzzz786@st.com/INBOX 
user/zzzz@po.com/INBOX 
user/zzzzaaaa@newdomain.com/INBOX 
user/zzzzz@syx.com/INBOX 
user/zzzzzr@strex.com/INBOX 
user/zzzzzz@newdomain.com/INBOX 
user/zzzzzz16@stre.com/INBOX 
user/zzzzzz7@bluo.com/INBOX 
user/zzzzzzz@newdomain.com/INBOX 
user/zzzzzzz@bppo.com/INBOX

# 7  
Old 08-16-2011
please use [code] tag, otherwise it is really hard to read it

---------- Post updated at 01:41 PM ---------- Previous update was at 01:23 PM ----------

put the patterns inside a text file ( for multiple patterns - line by line )
Code:
 
while read pattern
do
     sed -i 's/.*"$pattern".*//' file01.out         # sed -i will replace the contents
done < patternFile

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File transfer from UNIX to shared location using shell script

Is there any possible way transfering the file from unix to shared location using shell script. i had created the batch script to fetch the files from unix to shared location and it works fine. Due to some problem in windows unable to transfer the file to shared location automatically. can anyone... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

3. Shell Programming and Scripting

Shell script to read specified value from file and echo to the same location to other file.

Hello. I want to to backup some "default:" values from a file do some other job and after restore that "default:" values back. The problem is that the source and destination file has a lot of default: strings in it but with different values... So.. Here is an example: A part of my source... (6 Replies)
Discussion started by: ausdim
6 Replies

4. Shell Programming and Scripting

ksh using input file with output going to same file name and location

I've been asked if I can write a "quick" little ksh script that will do the following: java java_class_file /dir/input_file.xml /dir/output_file.xml I'm a complete newbie with ksh so any help would be appreciated. This is on AIX and java is found in /usr/java5/jre/bin/java (4 Replies)
Discussion started by: newbie_ksh
4 Replies

5. Shell Programming and Scripting

Shell Script - File Input/Output in C

This is part of my code: for in_file in $1/*.in # list of all .in files in working directory. do $c_file < $in_file > "$tempFile.out" if diff "$tempFile.out" $out_file >/dev/null 2>&1 ; then ... (6 Replies)
Discussion started by: spider-man
6 Replies

6. Shell Programming and Scripting

Asking user for input file location using a .sh file in windows system

Hi all, I am creating a .sh file in windows environment using notepad. i need a code which i can write in this .sh file so that it asks me for an input file stored anywhere in my C drive of my windows computer. Please help me out with this. (1 Reply)
Discussion started by: bansalpankaj88
1 Replies

7. Shell Programming and Scripting

Unzip the input file using shell script (ksh)

Hi, I need help in unziping input file through shell script. I had written script, which checks for input file extention. If Extension is "zip" or "gz", then I want to do unzip/uncompress that file. Caould you please let me know that, How to unzip a file through shell script (ksh). Thanks... (16 Replies)
Discussion started by: Poonamol
16 Replies

8. Shell Programming and Scripting

How to write shell script for input file name format checking?

Hello, I had written a shell script that accepts input file as cmd line argument and process this file. if ; then if ; then . $1 LOGFILE="$LOG_FILE/MIG_BIOS.log"; get_input_file else ERROR_CODE=MSCRM0005_003 error "$ERROR_CODE : Input file $1 is not available"; exit... (3 Replies)
Discussion started by: Poonamol
3 Replies

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

10. Shell Programming and Scripting

How to input username on text file into finger command on shell script

I'm trying to clean up my server and I have the list of some "special" users stored on the text file like this Now I want to write a shell script to finger all of them so I can have some kind of ideas who they are but here comes the problem....I completely forgot how to do it with shell... (3 Replies)
Discussion started by: Micz
3 Replies
Login or Register to Ask a Question