Sponsored Content
Top Forums Shell Programming and Scripting Finding a text in files & replacing it with unique strings Post 302762205 by gordom on Monday 28th of January 2013 08:35:13 AM
Old 01-28-2013
Quote:
Originally Posted by bakunin
First off, could you PLEASE stay away from the text formatting!
Sorry for that - it was unintentionally. I pasted a text from word processor - my mistake. The original post was already corrected.

Quote:
Originally Posted by bakunin
In this case the interpretable command would be "pattern1=abc" and "def" and "geh" would be treated as (indecipherable) other commands, which perhaps leads to some error message, in addition to "pattern1" not having the value you expect it to have.
That exactly what was happening.

Quote:
Originally Posted by bakunin
Code:
while IFS=";" read file pattern replacement ; do
     sed "s/${pattern}/${replacement}/" "$file" > tmpfile
     mv tmpfile "$file"
done

Quote:
Originally Posted by RudiC
Little to add to bakunin's explanations, except for the data source to read from: redirect input of the entire loop to your file.csv:... done < file.csv
In the end, thanks everyone for help. Specially bakunin & RudiC - the script seems to work perfect now. Great Smilie
Regards,
gordom
 

10 More Discussions You Might Find Interesting

1. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies

2. Shell Programming and Scripting

replacing strings with text from other file

Hi, Im trying to update some properties files with text from another file: file1 user=xyz file2 user= after script file2 user=xyz Im using this reading the $QUARTZURL,ETC... from quartz.properties: echo... (1 Reply)
Discussion started by: mc1392
1 Replies

3. Shell Programming and Scripting

help with finding & replacing pattern in a file

Hi everyone. Could u be so kind and help me with on "simple" shell script? 1. i need to search a file line by line for a pattern. example of a lines in that file 2947 domain = feD,id = 00 0A 02 48 17 1E 1D 39 DE 00 0E 00,Name Values:snNo = f10 Add AttFlag = 0 2. i need to find... (0 Replies)
Discussion started by: dusoo
0 Replies

4. UNIX for Dummies Questions & Answers

Finding & Replacing specific Fields

All I have a very large file (aproximately 150,000) as shown below separated by pipe "|". I need to replace data in 2, 16, 17, 23 fields that are of time stamp format. My goal is to look in those fields and it ends with "000000|" then replace it with "000|". In other words, make it as 6 digit... (2 Replies)
Discussion started by: ddraj2015
2 Replies

5. UNIX for Dummies Questions & Answers

Finding Unique strings which match pattern

I need to grep for a pattern in a file. Files are huge and have several repeated occurances of the strings which match pattern. I just need the strings which contain the pattern in the output. For eg. The contents of my file are as follows. The pattern I want to match by is ABCD ... (5 Replies)
Discussion started by: tektips
5 Replies

6. Homework & Coursework Questions

Finding/replacing text and redirection help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: What command would rename "sequentialInsert", in ~cs252/Assignments/commandsAsst/project/arrayops.h, to... (2 Replies)
Discussion started by: lothwen
2 Replies

7. Shell Programming and Scripting

Replacing variable Text between fixed strings

Hello all, This is my first post and I hope you can help me out. I searched for quite some hours now and haven't found a simple solution to my problem. It is as following: I got this file: dl.dropbox.com/u/14586156/stuff/Bookmarks.plist and want to replace the Text between... (9 Replies)
Discussion started by: pasc
9 Replies

8. Shell Programming and Scripting

Extended replacing of nonspecific strings in text files [beware complicated !]

Well, to make another post at this helpful forum :b::D: I recently tried something like this, I want to replace all those numberings/letters that are located between <string>file://localhost/var/mobile/Applications/ and /Documents/</string> numberings =---- replace with: first... (6 Replies)
Discussion started by: pasc
6 Replies

9. Shell Programming and Scripting

Finding/replacing strings in some files based on a file

Hi, We have a file (e.g. a .csv file, but could be any other format), with 2 columns: the old value and the new value. We need to modify all the files within the current directory (including subdirectories), so find and replace the contents found in the first column within the file, with the... (9 Replies)
Discussion started by: Talkabout
9 Replies

10. Shell Programming and Scripting

Command to show unique strings in two files

how to display the unique strings in two files using shell script or commands. I tried diff and cmp but it shows the entire line, i need only the mismatched strings. File1: sat,sun,mon,tue rose,lilly,lotus white,red,blue,green,pink File2: sat,sun,mon,tue rose,sunflower,lotus... (4 Replies)
Discussion started by: Arun_Linux
4 Replies
SHELL-QUOTE(1p) 					User Contributed Perl Documentation					   SHELL-QUOTE(1p)

NAME
shell-quote - quote arguments for safe use, unmodified in a shell command SYNOPSIS
shell-quote [switch]... arg... DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples. EXAMPLES
ssh preserving args When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and passes them to "$SHELL -c". This doesn't work as intended: ssh host touch 'hi there' # fails It creates 2 files, hi and there. Instead, do this: cmd=`shell-quote touch 'hi there'` ssh host "$cmd" This gives you just 1 file, hi there. process find output It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote: eval set -- `find -type f -print0 | xargs -0 shell-quote --` debug shell scripts shell-quote is better than echo for debugging shell scripts. debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" } With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can. save a command for later shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are things the user can't pass through), you can do something like this: user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args" OPTIONS
--debug Turn debugging on. --help Show the usage message and die. --version Show the version number and exit. AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions. AUTHOR
Roderick Schertler <roderick@argon.org> perl v5.8.4 2005-05-03 SHELL-QUOTE(1p)
All times are GMT -4. The time now is 09:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy