SED Newbie


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED Newbie
# 1  
Old 10-18-2006
SED Newbie

I'm trying to figure out how to basically replace a line in a text file using Sed. Here's what I need sed to do:

I have a file with passwords that are in use. Each month the passwords need to be swapped out with passwords stored in another file. I want to use Sed (or Awk ... or possibly both) to replace just the password section (look below).

pass:2432hkh49ncs9s <-- (I want to replace everything after the : delimiter )
7daypass:9g8ehv24v83hqs
99daypass:u4hkhv2.9zf67a

Ideally I would just like to make the line blank and then replace it with my password string. What I've tried so far is something like this:

sed 1s/pass:/ <--Then what I want to do is replace everything after pass:

I'm not sure if I've provided enough info, but any help would be greatly appreciated, thanks!
# 2  
Old 10-18-2006
Assumeing your new password file is formated with one password per line, something like this could work:

Code:
#!/bin/bash - 
# 
 
i=1 
lines=$(cat passfile | wc -l)   

while [ $i -le $lines ] ; do   
   pass=$(awk 'BEGIN { FS = "\n" ; RS = "" } { print '\$$i'  }' passlist)  
   sed -n ""$i"s/:.*/:$pass/pg" passfile 
   ((i++)) 
done

I guess I should've probably used a for loop, either or I guess:

Code:
#!/bin/bash - 
#  

for (( i = 1 ; i <= $(cat passfile | wc -l) ; i++))
   do
    pass=$(awk 'BEGIN { FS = "\n" ; RS = "" } { print '\$$i'  }' passlist)      
    sed -n ""$i"s/:.*/:$pass/pg" passfile
done


Last edited by petebear; 10-19-2006 at 12:57 AM..
# 3  
Old 10-19-2006
Thanks, that was exactly what I needed.
# 4  
Old 10-19-2006
You're welcome.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed newbie question

hi all: i am trying to use sed to separate hex bytes "363834574e292c20" to "36 38 34 57 4e 29 2c 20". i used the following script (googled) and i got "3 63 83 45 74 e2 92 c2 0". how could i modify the script to meet my needs? thanks (8 Replies)
Discussion started by: ipfreak
8 Replies

2. Shell Programming and Scripting

sed newbie scripting assistance

Howdy folks, I'm trying to craft a log file summarisation tool for an application that creates a lot of duplicate entries with only a different suffix to indicate point of execution. I thought I'd gotten close but I'm clearly missing something. Here's a genericized version: A text_file... (3 Replies)
Discussion started by: mthespian
3 Replies

3. Shell Programming and Scripting

newbie -- please help: sed

Hi I am trying to setup a sed script that will rename all files in a folder to their date and time stamp. eg: xxxxx.jpg xxxxx12.jpg xxxxx14.jpg they need to be renamed to upstairs `date +%Y%m%d`.jpg They have no metadata, so cannot use exif, will need to use sed. Thanks... (2 Replies)
Discussion started by: akmodi
2 Replies

4. UNIX for Dummies Questions & Answers

Sed Newbie Question

Hello everyone I could really need some help. I want to rename : with dot. But the problem is that i don't want to touch the hours like 12:00 but i want to change AD:FG with AD.FG. I'm thinking something like : to . I don't know if i explain it corrrectly but i could use some help Thanks... (20 Replies)
Discussion started by: zoe
20 Replies

5. Shell Programming and Scripting

perl newbie . &&..programming newbie

Hi, I am new to programming and also to perl..But i know 'perl' can come to my rescue, But I am stuck at many places and need help..any small help is much appreciated... below is the description of what i intend to acheive with my script. I have a files named in this format... (13 Replies)
Discussion started by: xytiz
13 Replies

6. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

7. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

8. Shell Programming and Scripting

SED question: newbie here.

Hello... I wanted to figure out how to remove the 1st instance of a comma from a file.. 100+ line file ------------- 'test1' ,'dudes are cool' <-- remove comma from first instance of comma in file ,'cool dude' ,'bbbbbb' I tried everything from cat jigar|tr , >1.txt to cat jigar|sed... (2 Replies)
Discussion started by: jigarlakhani
2 Replies

9. Shell Programming and Scripting

Need Help with AWK or SED (Newbie)

Hello, I have a text file in below format, how do I put a header and assign field names to the file with either AWK or SED STRT~ VA ~23606 ~TM14~8506~1485 (page 1) STRT~ VA ~23662 ~TM17~8362~1783 (page 2) STRT~ VA ~23662 ~TM17~8362~1783 STRT~ VA ~23662 ~TM17~8362~1783 STRT~ VA ~23662... (1 Reply)
Discussion started by: udaybo
1 Replies

10. Shell Programming and Scripting

Newbie using sed in a shell script

I'm sure this is an easy one but I can't seem to get it working. Given the following: for oldName in `ls *.JPG` ;do newName=<confusion here. how to make sed perform 's/.JPG/_thumb.JPG/g' operation on $oldName> done Could someone show me what I'm doing wrong? Thanks Ken (1 Reply)
Discussion started by: ktoz
1 Replies
Login or Register to Ask a Question