sed trouble


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed trouble
# 1  
Old 09-05-2008
sed trouble

Hello

I use sed to insert text into files in unix shell scripts and I've noticed that sed create empty files such as
sed6OAPQ6, sedioICv3, sedOYkVW6, sedu1yKVY, etc.

Whay sed creates these files and how to fix this issue?

thanks in advance

rgds

Teo
# 2  
Old 09-05-2008
Show your sed code please.
# 3  
Old 09-05-2008
This is a sed sample I use

for m in `awk '$0 ~ /urlWebservice/ {print}' ./localConfiguration.conf`
do
if [ -n "$m" ] ; then
t=`echo $m | cut -d"=" -f1`
for j in `awk '$0 ~ /'$t'/ {print}' $file`
do
s=`echo $j | grep http`
if [ -n "$s" ] ; then
sed -i 's#^'$t'.*#'$m'#' $file
fi
done
fi
done
# 4  
Old 09-05-2008
I don't see any point in this script where anything is redirected into a file for example. So I guess it is not this script or part of a script producing those empty files.

You can add a "set -x" in the beginning to check what it is doing maybe.

Are you sure no other script creating those empty files or is there missing something from that script?
Maybe delete those empty files and execute the lines you just posted and see if they are there again, just to be sure.

Btw., there are [ code ] and [ /code ] tags available in this forum to post code a bit more readable.
# 5  
Old 09-05-2008
This is just a part of the sed use. I'll try to use -x option to get more info.

thanks
# 6  
Old 09-05-2008
As a matter of style and maintainability, you probably want to replace the awk scripts with grep, and use while instead of for.

Code:
grep urlWebservice ./localConfiguration.conf |
while read m; do
  t=${m%=*}
  grep "$t" $file |
  while read j; do
    case $j in *http*)  sed -i 's#^'"$t"'.*#'"$m"'#' $file;; esac
  done
done

Something outside of this part of the script is responsible for setting $file so that is my guess at the culprit.

If there are multiple occurrences of $t in a file, you needlessly perform the same substitution multiple times. Perhaps you simply want to check whether $file contains $t and "http", and if so, perform the replacement once?

Code:
if grep "$t" $file | grep http >/dev/null; then
  sed -i 's#^'"$t"'.*#'"$m"'#' "$file"
fi


Last edited by era; 09-05-2008 at 08:50 AM.. Reason: Implement suggestion to only perform substitution once
# 7  
Old 09-05-2008
Thanks for your answerSmilie

I didn't post all the script. I don't understand why $file is the culprit.
May be it's due to the use of g option for replacement. Not sure.

I believe that the empty files called sedXX could be the temporary data buffer used by sed.

Teo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble using awk and sed commands

Hi i have a control file which i need to read. It is ',' separated. the 3rd parameter will be ';' separated. I have 2 files: /home/orig.txt /home/join.txt I need a O/P file name based on firstparameter_1.txt and it should have the content of /home/orig.txt and appended content from... (2 Replies)
Discussion started by: Ravindra Swan
2 Replies

2. Shell Programming and Scripting

Trouble with passing variable to sed

Here is my code #!/bin/bash username=gnowicki sed '$s/$/ $username/' < sshd_config 1 <> sshd_config what this is supposed to do is take the name gnowicki and put it at the end of the last line of the sshd_config and it works except not using the variable, if I put the name "gnowicki" where... (2 Replies)
Discussion started by: slufoot80
2 Replies

3. Shell Programming and Scripting

Trouble with sed and substituting a string with special characters in variable

Hey guys, I know that title is a mouthful - I'll try to better explain my struggles a little better... What I'm trying to do is: 1. Query a db and output to a file, a list of column data. 2. Then, for each line in this file, repeat these values but wrap them with: ITEM{ ... (3 Replies)
Discussion started by: ampsys
3 Replies

4. Shell Programming and Scripting

Trouble with sed and ini file parsing

hi people, i'm having a hard time trying to extract a list of vars delimited by section inside a ini file ... let's consider this ini file : ; config file DESC = "channel synchro TGG01" DMM_VER = DMM23 PATH_FIFO = /users/tgg00/fifo QRT = BTS01.TGG.01.2 MODE_TRACE... (5 Replies)
Discussion started by: odium74
5 Replies

5. Shell Programming and Scripting

sed multiple line trouble

Hello, im writing a script that validates a URL (the parameter) using http://validator.w3.org first it downloads the site (the output line I want is stored in the h2 field of the site's html. wget http://validator.w3.org/check?url=$1 2> /dev/null sed -n '/<h2/p' check?uri=$1 | sed 's/... (5 Replies)
Discussion started by: drareeg
5 Replies

6. Shell Programming and Scripting

assigning SED output to a variable = trouble!

i'm on a Mac running BSD unix. i have a script in which i ask the user to input the name of a mounted volume. i then call SED to substitute backslashes and spaces in place of the spaces. that looks like this: echo "Enter the name of the volume" read Volume echo "You've chosen \"$Volume\""... (7 Replies)
Discussion started by: hungryd
7 Replies

7. UNIX for Dummies Questions & Answers

X trouble

Hi there, I'm new to unix-environments. I'm richard, and i'm mostly a web-developer, under php. I've done work in unix env before, but never had my own. Today, I've got debian 3.1 r4 from the official site, and i've attempted to install it twice. I installed it initially as "Desktop... (0 Replies)
Discussion started by: izua
0 Replies

8. Solaris

Trouble with tr

I'm not sure where to post this but it's happening on a SunOS 5.8 server so I'll try here. I've discovered some unexpected behavior when using tr. For example: echo a | tr Z echo b | tr a echo a | tr B echo a | tr B echo a | tr A (8 Replies)
Discussion started by: Mike@Work
8 Replies

9. What is on Your Mind?

The trouble with...

Welcome to "The trouble with...." with your host, ZazzyBob. Todays offering - "The trouble with letting other people host your website" I use a certain web hosting service, who shall of course remain nameless here. They are running PHP 4.3.10 I decide to write a script to test their PHP... (6 Replies)
Discussion started by: zazzybob
6 Replies

10. UNIX Desktop Questions & Answers

trouble

Hello, The system reboots in single user mode what command to use to bring the system up regularly?? I get INIT: cannot create /var/adm/utmpx Type control -d to proceede with a normal startup or give root passwd for system maintaince. either way i don't have a change and ... (1 Reply)
Discussion started by: awk
1 Replies
Login or Register to Ask a Question