Sponsored Content
Top Forums Shell Programming and Scripting need help on sed (replace string without changing filename) Post 57351 by encrypted on Sunday 24th of October 2004 04:58:31 AM
Old 10-24-2004
I personaly prefer perl for string replacement instead of sed

#/bin/bash
printf "Enter the String to be replaced: "
read ostring
printf "Enter the String to be substituted: "
read rstring
printf "Enter the Path of the files: "
read path
cd $path
files = `ls`
for file in $files
do
perl -p -i -e 's/$ostring/$rstring/' $file
done

Chill
enc;-)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse and replace string in filename

Hi, I've a filename of this format: "XXX_XXX_TXT.TAR.AS". Need to change the name into this format: "XXX_XXX.TAR.AS". This file resides in a directory. I'm ok with using the find command to search and display it. Essentially I just need to replace the string "_TXT.TAR.AS" to ".TAR.AS". Is awk... (17 Replies)
Discussion started by: chengwei
17 Replies

2. Shell Programming and Scripting

Replace a filename with full path using sed

hi, i need to replace a line a file with a new raw device location.. original file.. /opt/sybase/ASE1502/ASE-15_0/bin/dataserver \ -d/data/TST_AKS1/sybdevices/master.dat \ -e/logs/sybase/TST_AKS1/SFO_TST_AKS1.log \ -c/apps/sybase/ASE1502/ASE-15_0/TST_AKS1.cfg \... (2 Replies)
Discussion started by: aksaravanan
2 Replies

3. Shell Programming and Scripting

extract string portion from filename using sed

Hi All, I posted something similar before but I now have a another problem. I have filenames as below TOP_TABIN240_20090323.200903231830 TOP_TABIN235_1_20090323.200903231830 i need to extract the dates as in bold. Using bash v 3.xx Im trying to using the print sed command but... (11 Replies)
Discussion started by: santam
11 Replies

4. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

5. UNIX for Dummies Questions & Answers

replace multiple patterns in a string/filename

This should be somewhat simple, but I need some help with this one. I have a bunch of files with tags on the end like so... Filename {tag1}.ext Filename2 {tag1} {tag2}.ext I want to hold in a variable just the filename with all the " {tag}" removed. The tag can be anything so I'm looking... (4 Replies)
Discussion started by: kerppz
4 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

sed to replace pattern with filename

Hi all, I'm trying to replace a pattern/string in about 100 files with the filename using following commands but getting nowhere: for f in *.fa; do sed "s/^>.*/>$f/g" $f > $f_v1.fa; done for f in *.fa; do sed 's/^>.*/>`echo $f`/' > $fa_v1.fa; done Basically I want to change any line... (5 Replies)
Discussion started by: ivpz
5 Replies

9. UNIX for Dummies Questions & Answers

Sed- Replace space in filename by a \

`echo $file | sed 's/ / /g'` Hey guys I want help in converting the spaces in my file names to '\ ' . Example: UK maps --> UK\ maps Could someone please help me. I have tried the following sequences already (none of them work): 1)s/ /\ /g 2)s/ /\\ /g 3)s/ /\\\ /g Can someone... (7 Replies)
Discussion started by: INNSAV1
7 Replies

10. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies
errno(5)							File Formats Manual							  errno(5)

NAME
errno - Returns error condition value SYNOPSIS
#include <errno.h> DESCRIPTION
The errno external variable contains the most recent error condition set by a function. The symbolic values for errno are listed in the intro reference page and in the ERRORS section of the individual reference pages for each function. The exec() functions set errno to a value of 0 (zero) after successful completion. Typically, other functions only set errno to a nonzero value. EXAMPLES
The following program uses the value of errno to determine why the requested file could not be opened. If errno has one of the two tested values, the program prints an appropriate message; otherwise, the program uses the error() function to print out the appropriate message. This program does not have to set errno to a value of 0 (zero) because errno is tested only if the open() function has failed. #include <errno.h> #include <stdio.h> #include <string.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #define SLENGTH 80 main() { char filespec[SLENGTH], *eol; int opret; while (TRUE) { printf("Enter file to be checked: "); fgets(filespec, SLENGTH, stdin); if ((eol = strchr(filespec, ' ')) != NULL) { *eol = ''; /* Replace newline with null */ if (*filespec == '') return; /* exit program */ opret = open(filespec,O_RDONLY,0); if (opret > 0) printf("%s: File exists ",filespec); else if (errno == ENOENT) printf("%s: File does not exist ",filespec); else if (errno == ENOTDIR) printf("%s: Prefix in path is not a directory ", filespec); else perror(filespec); } else /* Line entered too long */ printf("Line entered is too long "); } } NOTES
To ensure that your programs are portable, you should not explicitly declare errno to be an extern int in your program. You should rely on the type int declaration in the <errno.h> include file. Full use. SEE ALSO
Functions: intro(2), perror(3), strerror(3) errno(5)
All times are GMT -4. The time now is 03:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy