Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help with replacing characters without moving the spaces. Post 303038072 by MadeInGermany on Friday 23rd of August 2019 01:02:50 PM
Old 08-23-2019
Maybe not doable with sed.
But with awk:
Code:
awk -v field=2 -v oldval="VALUE2" -v newval="VALUETEST"  -F"|"  '$field~oldval { $field=newval } { printf "%s|%-15s|%s\n", $1, $2, $3 }' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing tabs to spaces from files

hi, I have some 50 C files in which for indentation of code some devlopers used tabs, but we dont want any tab used for indentation. I have following 2 need. 1) find tabs from all 50 files (which are in one directory ) 2) replace them with 4 spaces. Thanks Rishi (6 Replies)
Discussion started by: rishir
6 Replies

2. Shell Programming and Scripting

need help in replacing spaces in a file

hi all this is the part i am facing a problem eg data: filename : tr1 + T 40 this is a sample record in that file ... the value of T can be anything, but will be a single character. i need to cut from field two, and i am using this command cut -d " " -f2 tr1 >tr3 and the o/p is ... (7 Replies)
Discussion started by: sais
7 Replies

3. UNIX for Dummies Questions & Answers

Replacing the Spaces

Hi, i have a tab dilimeted file.The records are :header is having column names.I am facing the following issue : I want to convert the spaces only for header file into "_" in the unix shell but the problem is that if i use sed command all the blank spaces are getting replaced by "_". For... (3 Replies)
Discussion started by: Amey Joshi
3 Replies

4. Shell Programming and Scripting

Moving filenames containing spaces

I want to ftp all the sh files in the directory. Also if any of the file name contains spaces in them, it should be converted to underscores before it is ftped. I wrote the following code below: FILESSH=$(ls /mysh/*.sh) --- FILESH being used here for some other task --- echo "$FILESSH" |... (3 Replies)
Discussion started by: amicon007
3 Replies

5. Shell Programming and Scripting

moving files with spaces in filename from one directory to another

Hello, When I run following script #!/bin/bash cd ~/directory1 mv `ls -trF | grep -v / | tail -10 ` ~/directory2 works fine with filenames not having any space but runs into issues with filenames that have spaces tried with $file variable still doesnot work. Can someone help me (4 Replies)
Discussion started by: asakhare
4 Replies

6. Shell Programming and Scripting

trim spaces and replacing value

Hi, I have a file origFile.txt with values: origFile.txt .00~ 145416.02~ xyz~ ram kishor ~? ~ ~783.9 .35~ 765.76~ anh reid~ kelly woodburg ~nancy ~ ~? Now each row in the file has value for 7 columns with "~" as delimiter. The requirement was i)I need to erase the blank spaces between... (2 Replies)
Discussion started by: badrimohanty
2 Replies

7. Shell Programming and Scripting

Replacing the new character with spaces

Hi Experts, We are facing some while loading the "csv" file to target table.Some of the records are having values as : Account number,Name,Address "123","XYZ","302 Street,Washington,US" "456","PQR"," 3233 Some Street, Washington,US" In the above file instead reading only two records it... (11 Replies)
Discussion started by: Amey Joshi
11 Replies

8. Shell Programming and Scripting

Replacing tabs with spaces

I want my program to replace tabs with spaces.1tab=4spaces.When i write aa(tab)aaa(tab)(tab)a(tab) it must show me aaxxaaaxxxxxaxxx. I think that my program works corectly but when a write aaa(tab)a it must show aaaxa but it is aaaxxxxxa.Please for help!!! That is my code: #include <stdio.h> ... (3 Replies)
Discussion started by: marto1914
3 Replies

9. Shell Programming and Scripting

Moving files that contain spaces...

I have a script that I've written and it's been running fine until someone dropped a file in the source directory that had spaces in it. The script breaks the file name into separate mv commands. I've tried putting " around the $FILE but that didn't help. Anyone who can help me would be greatly... (8 Replies)
Discussion started by: Sanglant
8 Replies

10. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies
apache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR:User(Contributed Perl Documapache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR::URI(3)

NAME
APR::URI - Perl API for URI manipulations Synopsis use APR::URI (); my $url = 'http://user:pass@example.com:80/foo?bar#item5'; # parse and break the url into components my $parsed = APR::URI->parse($r->pool, $url); print $parsed->scheme; print $parsed->user; print $parsed->password; print $parsed->hostname; print $parsed->port; print $parsed->path; print $parsed->rpath; print $parsed->query; print $parsed->fragment; # reconstruct the url, after changing some components and completely # removing other $parsed->scheme($new_scheme); $parsed->user(undef); $parsed->password(undef); $parsed->hostname($new_hostname); $parsed->port($new_port); $parsed->path($new_path); $parsed->query(undef); $parsed->fragment(undef); print $parsed->unparse; # get the password field too (by default it's not revealed) use APR::Const -compile => qw(URI_UNP_REVEALPASSWORD); print $parsed->unparse(APR::Const::URI_UNP_REVEALPASSWORD); # what the default port for the ftp protocol? my $ftp_port = APR::URI::port_of_scheme("ftp"); Description "APR::URI" allows you to parse URI strings, manipulate each of the URI elements and deparse them back into URIs. All "APR::URI" object accessors accept a string or an "undef" value as an argument. Same goes for return value. It's important to distinguish between an empty string and "undef". For example let's say your code was: my $uri = 'http://example.com/foo?bar#item5'; my $parsed = APR::URI->parse($r->pool, $uri); Now you no longer want to the query and fragment components in the final url. If you do: $parsed->fragment(''); $parsed->query(''); followed by: my $new_uri = parsed->unparse; the resulting URI will be: http://example.com/foo?# which is probably not something that you've expected. In order to get rid of the separators, you must completely unset the fields you don't want to see. So, if you do: $parsed->fragment(undef); $parsed->query(undef); followed by: my $new_uri = parsed->unparse; the resulting URI will be: http://example.com/foo As mentioned earlier the same goes for return values, so continuing this example: my $new_fragment = $parsed->fragment(); my $new_query = $parsed->query(); Both values now contain "undef", therefore you must be careful when using the return values, when you use them, as you may get warnings. Also make sure you read through "the unparse() section" as various optional flags affect how the deparsed URI is rendered. API
"APR::URI" provides the following functions and/or methods: "fragment" Get/set trailing "#fragment" string $oldval = $parsed->fragment($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) since: 2.0.00 "hostinfo" Get/set combined "[user[:password]@]host[:port]" $oldval = $parsed->hostinfo($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) since: 2.0.00 The "hostinfo" value is set automatically when "parse()" is called. It's not updated if any of the individual fields is modified. It's not used when "unparse()" is called. "hostname" Get/set hostname $oldval = $parsed->hostname($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) since: 2.0.00 "password" Get/set password (as in http://user:password@host:port/) $oldval = $parsed->password($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) since: 2.0.00 "parse" Parse the URI string into URI components $parsed = APR::URI->parse($pool, $uri); obj: $parsed ( "APR::URI object or class" ) arg1: $pool ( string ) ( "APR::Pool object" ) arg2: $uri ( string ) The URI to parse ret: $parsed ( "APR::URI object or class" ) The parsed URI object since: 2.0.00 After parsing, if a component existed but was an empty string (e.g. empty query http://hostname/path?) -- the corresponding accessor will return an empty string. If a component didn't exist (e.g. no query part http://hostname/path) -- the corresponding accessor will return "undef". "path" Get/set the request path $oldval = $parsed->path($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) "/" if only "scheme://host" since: 2.0.00 "rpath" Gets the "path" minus the "path_info" $rpath = $parsed->rpath(); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) The path minus the path_info since: 2.0.00 "port" Get/set port number $oldval = $parsed->port($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( number or string or undef ) ret: $oldval ( string or undef ) If the port component didn't appear in the parsed URI, APR internally calls "port_of_scheme()" to find out the port number for the given "scheme()". since: 2.0.00 "port_of_scheme" Return the default port for a given scheme. The recognized schemes are http, ftp, https, gopher, wais, nntp, snews and prospero. $port = APR::URI::port_of_scheme($scheme); obj: $scheme ( string ) The scheme string ret: $port (integer) The default port for this scheme since: 2.0.00 "query" Get/set the query string (the part starting after '?' and all the way till the end or the '#fragment' part if the latter exists). $oldval = $parsed->query($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) since: 2.0.00 "scheme" Get/set the protocol scheme ("http", "ftp", ...) $oldval = $parsed->scheme($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) since: 2.0.00 "user" Get/set user name (as in http://user:password@host:port/) $oldval = $parsed->user($newval); obj: $parsed ( "APR::URI object" ) opt arg1: $newval ( string or undef ) ret: $oldval ( string or undef ) since: 2.0.00 "unparse" Unparse the URI components back into a URI string $new_uri = $parsed->unparse(); $new_uri = $parsed->unparse($flags); obj: $parsed ( "APR::URI object" ) opt arg1: $flags ( the APR::Const :uri constants ) By default the constant "APR::Const::URI_UNP_OMITPASSWORD" is passed. If you need to pass more than one flag use unary "|", e.g.: $flags = APR::Const::URI_UNP_OMITUSER|APR::Const::URI_UNP_OMITPASSWORD; The valid "flags" constants are listed next ret: $new_uri ( string ) since: 2.0.00 Valid "flags" constants: To import all URI constants you could do: use APR::Const -compile => qw(:uri); but there is a significant amount of them, most irrelevant to this method. Therefore you probably don't want to do that. Instead specify explicitly the ones that you need. All the relevant to this method constants start with "APR::URI_UNP_". And the available constants are: "APR::Const::URI_UNP_OMITSITEPART" Don't show "scheme", "user", "password", "hostname" and "port" components (i.e. if you want only the relative URI) "APR::Const::URI_UNP_OMITUSER" Hide the "user" component "APR::Const::URI_UNP_OMITPASSWORD" Hide the "password" component (the default) "APR::Const::URI_UNP_REVEALPASSWORD" Reveal the "password" component "APR::Const::URI_UNP_OMITPATHINFO" Don't show "path", "query" and "fragment" components "APR::Const::URI_UNP_OMITQUERY" Don't show "query" and "fragment" components Notice that some flags overlap. If the optional $flags argument is passed and contains no "APR::Const::URI_UNP_OMITPASSWORD" and no "APR::Const::URI_UNP_REVEALPASSWORD" -- the "password" part will be rendered as a literal "XXXXXXXX" string. If the "port" number matches the "port_of_scheme()", the unparsed URI won't include it and there is no flag to force that "port" to appear. If the "port" number is non-standard it will show up in the unparsed string. Examples: Starting with the parsed URL: use APR::URI (); my $url = 'http://user:pass@example.com:80/foo?bar#item5'; my $parsed = APR::URI->parse($r->pool, $url); deparse it back including and excluding parts, using different values for the optional "flags" argument: o Show all but the "password" fields: print $parsed->unparse; Prints: http://user@example.com/foo?bar#item5 Notice that the "port" field is gone too, since it was a default "port" for "scheme" "http://". o Include the "password" field (by default it's not revealed) use APR::Const -compile => qw(URI_UNP_REVEALPASSWORD); print $parsed->unparse(APR::Const::URI_UNP_REVEALPASSWORD); Prints: http://user:pass@example.com/foo?bar#item5 o Show all fields but the last three, "path", "query" and "fragment": use APR::Const -compile => qw(URI_UNP_REVEALPASSWORD APR::Const::URI_UNP_OMITPATHINFO); print $parsed->unparse( APR::Const::URI_UNP_REVEALPASSWORD|URI_UNP_OMITPATHINFO); Prints: http://user:pass@example.com See Also "Apache2::URI", mod_perl 2.0 documentation. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.16.2 2011-02-07 apache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR::URI(3)
All times are GMT -4. The time now is 11:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy