sed or unix question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed or unix question
# 1  
Old 04-15-2009
Tools sed or unix question

hello,

i have a csh file that calls a program and stores the output in a variable. the output is:
Code:
\*\%VFT\$1\\3

as you can see there is a backslash before every non alphanumeric character. i save this output and then use SED to replace a word in a file with the output that i got.

however, after replacing the word when i look at the file the characters are: *%VFT$1\3 instead of \*\%VFT\$1\\3

i believe this is due to unix or csh or sed using backslash as escape character.

code below:
Code:
#!/bin/csh -f
set word = `applicationName parameter | awk 'NR==5 {print $9}'`  
# this saves \*\%VFT\$1\\3 in variable word 
# backslash before all non alphanumeric character
echo "$word"
sed  "s/iamuser/"$passwd"/g" < cshrc_Dev_Template > cshrcTest
# file cshrc_Dev_Template contains only one line which is below
# setenv TESTPASSWD iamuser

when i look into cshrcTest there is only one line below

Code:
setenv TESTPASSWD *%VFT$1\3

and i need to have a backslash before any non alphanumeric character.

Last edited by Yogesh Sawant; 04-16-2009 at 04:37 AM.. Reason: added code tags
# 2  
Old 04-17-2009
sed is doing that. but let's back up for a second. you can do this (probably) with awk:
Code:
set word = `applicationName parameter | awk 'NR==5 {print $9}'`

So that's the output of the application into awk, and you want it to print out the 9th field of the 5th line, then you want to use that instead of the 3rd field of the line "setenv TESTPASSWD iamuser". You could just do:
Code:
applicationName parameter | awk 'NR==5 { print "setenv TESTPASSWD " $9; exit; }' > cshrcTest

# 3  
Old 04-20-2009
no can do

hello,

the reason i can't do that is because the command below will actually look in to the file cshrc_Dev_Template and replace 'iamuser' with the given password...then store into cshrcTest. The problem is that i need to replace iamuser, with password. not just add the password into the file.
sed "s/iamuser/"$passwd"/g" < cshrc_Dev_Template > cshrcTest
# 4  
Old 04-21-2009
In your original (pseudo?) code, you never output the user's id, so I don't see why that makes a difference. You are simply appending a line of output to a Test file. The password is coming from the application. Look at your original post again, and tell me how what you are now asking for makes sense.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed question

have some data and I'm attempting to manipulate with sed with not much success. Name John Davis Phone 5555555 Name Tim Watson Phone 1111111 would like to get that data to sort like this John Davis 5555555 Tim Watson 1111111 gotten sed to search for the value below 'Name'... (5 Replies)
Discussion started by: jimmyf
5 Replies

2. Shell Programming and Scripting

sed question

I have a text file that contains ascii text. Each line contains square brackets with text inside. I want to remove the square brackets AND the text inside them. So the lines of text look like this: I have tried: sed 's/\//g' and variations of that, but it doesn't work. Any help... (3 Replies)
Discussion started by: stumpyuk
3 Replies

3. Shell Programming and Scripting

Sed Question 1. (Don't quite know how to use sed! Thanks)

Write a sed script to extract the year, rank, and stock for the most recent 10 years available in the file top10_mktval.csv, and output in the following format: ------------------------------ YEAR |RANK| STOCK ------------------------------ 2007 | 1 | Exxon... (1 Reply)
Discussion started by: beibeiatNY
1 Replies

4. Shell Programming and Scripting

Easy unix/sed question that I could have done 10 years ago!

Hi all and greetings from Ireland! I have not used much unix or awk/sed in years and have forgotten a lot. Easy enough query tho. I am cleansing/fixing 10,000 postal addresses using global replacements. I have 2 pipe delimited files , one is basically a spell checker for geographical... (4 Replies)
Discussion started by: dewsbury
4 Replies

5. Shell Programming and Scripting

SED question

Hello there, I've seen quite a few post on SED to handle newline, but I tried few things doesn't seem to work. I was able to replace any tex tto newline, however viceversa (new line on Solaris returns error message as 'SED garbled".. sed 's/\ /#/g' f2 My source data looks like below... (6 Replies)
Discussion started by: brainyoung
6 Replies

6. Shell Programming and Scripting

sed question

Hi, :) can any body explain the following statement sed 's/\(\)- ]//g' cheers RRK (3 Replies)
Discussion started by: ravi raj kumar
3 Replies

7. Shell Programming and Scripting

Question on sed

In Linux: when I say sed 's/NAME1=test1/NAME1=test1\nNAME2=test2/g' filename > ./tmpfile Output: NAME1=test1 NAME2=test2 But in Solaris, I am getting: NAME1=test1nNAME2=test2 I want the output in solaris as in linux. Please advise. Thanks Chiru (5 Replies)
Discussion started by: chiru_h
5 Replies

8. UNIX for Dummies Questions & Answers

Unix History Question: Why are filenames/dirnames case sentsitive in Unix?

I tried looking for the answer online and came up with only a few semi-answers as to why file and directory names are case sensitive in Unix. Right off the bat, I'll say this doesn't bother me. But I run into tons of Windows and OpenVMS admins in my day job who go batty when they have to deal... (3 Replies)
Discussion started by: deckard
3 Replies

9. Shell Programming and Scripting

sed question

all, I am trying to write a script that will dynamically change passwords within a group of files. Each file will have a record such as PASSWORD="xxxxxxxxx". I plan on creating a file with a list of passwords, (say 500,000) and then writing a 'for' loop that will cycle thru each, and replace... (5 Replies)
Discussion started by: hedrict
5 Replies

10. IP Networking

unix to unix serial connection question

hi there i'm a new bie just got few simple questions to ask. I got expert in windows configuration but totally new to unix environment . I want to make sure a com port (com1) is working, so I connect a 9-pin cable (CB9) for both PC using Unix environment (unix to unix). The question are (1)... (1 Reply)
Discussion started by: typsam
1 Replies
Login or Register to Ask a Question