Sponsored Content
Top Forums Shell Programming and Scripting awk - How to preserve whitespace? Post 302767387 by Chubler_XL on Wednesday 6th of February 2013 06:49:31 PM
Old 02-06-2013
Try this one as well:

Code:
awk '
function rep(a,v) {
  sub("^(([^ \t]+[ \t]+){"a-1"})","&" SUBSEP);
  sub(SUBSEP "[^ \t]+", v);
}   
/^\// {
    rep(3,"13")
    rep(4,"*")
    rep(5,"$W1")
} 1' newsyslog.conf

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to assign value to variable using awk coz of whitespace in value

Unix gurus, I have a file as below, which is basically the result set obtained from a sql query on an Oracle database. ID PROG_NAME USER_PROG_NAME -------- --------------- ---------------------------------------- 33045 INCOIN Import Items 42690 ... (3 Replies)
Discussion started by: sunpraveen
3 Replies

2. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

3. Shell Programming and Scripting

Preserve space in variable of AWK

This seems to be a stupid basic question, but I cant get the space to stick in the awk variable. I do use this command to grep a time range of the log file. cat /var/log/daemon.log | awk '$0>=from&&$0<=to' from="$(date +%b" "%e" "%H:%M:%S -d -24hour)" to="$(date +%b" "%e" "%H:%M:%S)" I now... (9 Replies)
Discussion started by: Jotne
9 Replies

4. Shell Programming and Scripting

Date Format - preserve whitespace

I am trying to change the date format for the following: YESTER=`TZ=aaa24 date +%b" "%d | sed 's/0/ /'` TraceList=$(ls -ltR /pdt/logs | grep "$YESTER" | awk '{print $9}') CMD2=$(find /disk/dan/dansFiles/pass/logs/$TList -name cmd\* -prune) what I am trying to do in the above... (1 Reply)
Discussion started by: ther2000
1 Replies

5. Shell Programming and Scripting

Preserve trailing whitespace in variable

Hello, I wondering how I can echo a string without having the trailing whitespace removed. For example I have a string str="TESTING123 " that I need to hash using sha1. I get the correct answer when I run the line below from the terminal $ echo -n "TESTING123 " | openssl sha1... (3 Replies)
Discussion started by: colinireland
3 Replies

6. UNIX for Dummies Questions & Answers

[Solved] How remove leading whitespace from xml (sed /awk?)

Hi again I have an xml file and want to remove the leading white space as it causes me issues later in my script I see sed is possible but cant seem to get it to work I tried sed 's/^ *//' file.xml output <xn:VsDataContainer id="1U104799" modifier="update"> ... (10 Replies)
Discussion started by: aniquebmx
10 Replies

7. Shell Programming and Scripting

How to preserve spaces in input fields with awk?

I'm trying to do something pretty simple but its appears more complicated than expected... I've lines in a text file, separated by the comma and that I want to output to another file, without the first field. Input file: file1,item, 12345678 file2,item, 12345678 file2,item, ... (8 Replies)
Discussion started by: Armoric
8 Replies

8. Shell Programming and Scripting

Awk: Dealing with whitespace in associative array indicies

Is there a reliable way to deal with whitespace in array indicies? I am trying to annotate fails in a database using a table of known fails. In a begin block I have code like this: # Read in Known Fail List getline < "'"$failListFile"'"; getline < "'"$failListFile"'"; getline <... (6 Replies)
Discussion started by: Michael Stora
6 Replies

9. Shell Programming and Scripting

awk to ignore whitespace in field

The awk below executes and update the desired field in my first awk. However, the white space between nonsynonymous SNV in $9 is being split into tabs and my attempt to correct this does not update the field unless it is removed. I am not sure what I am doing wrong? Thank you :). file1 ... (4 Replies)
Discussion started by: cmccabe
4 Replies

10. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies
array(2rheolef) 						    rheolef-6.1 						   array(2rheolef)

NAME
array - container in distributed environment (rheolef-6.1) SYNOPSYS
STL-like vector container for a distributed memory machine model. EXAMPLE
A sample usage of the class is: int main(int argc, char**argv) { environment distributed(argc, argv); array<double> x(distributor(100), 3.14); dout << x << endl; } The array<T> interface is similar to those of the std::vector<T> with the addition of some communication features in the distributed case: write accesses with entry/assembly and read access with dis_at. DISTRIBUTED WRITE ACCESS
Loop on any dis_i that is not managed by the current processor: x.dis_entry (dis_i) = value; and then, after loop, perform all communication: x.dis_entry_assembly(); After this command, each value is stored in the array, available the processor associated to dis_i. DISTRIBUTED READ ACCESS
First, define the set of indexes: std::set<size_t> ext_idx_set; Then, loop on dis_i indexes that are not managed by the current processor: ext_idx_set.insert (dis_i); After the loop, performs the communications: x.set_dis_indexes (ext_idx_set); After this command, each values associated to the dis_i index, and that belongs to the index set, is now available also on the current pro- cessor as: value = x.dis_at (dis_i); For convenience, if dis_i is managed by the current processor, this function returns also the value. NOTE
The class takes two template parameters: one for the type T and the second for the memory model M, that could be either M=distributed or M=sequential. The two cases are associated to two diferent implementations, but proposes exactly the same interface. The sequential inter- face propose also a supplementary constructor: array<double,sequential> x(local_size, init_val); This constructor is a STL-like one but could be consufused in the distributed case, since there are two sizes: a local one and a global one. In that case, the use of the distributor, as a generalization of the size concept, clarify the situation (see distributor(2)). IMPLEMENTATION NOTE
"scatter" via "get_dis_entry". "gather" via "dis_entry(dis_i) = value" or "dis_entry(dis_i) += value". Note that += applies when T=idx_set where idx_set is a wrapper class of std::set<size_t> ; the += operator represents the union of a set. The operator= is used when T=double or others simple T types without algebra. If there is a conflict, i.e. several processes set the dis_i index, then the result of operator+= depends upon the order of the process at each run and is not deterministic. Such ambiguous behavior is not detected yet at run time. IMPLEMENTATION
template <class T, class A> class array<T,sequential,A> : public smart_pointer<array_seq_rep<T,A> > { public: // typedefs: typedef array_seq_rep<T,A> rep; typedef smart_pointer<rep> base; typedef sequential memory_type; typedef typename rep::size_type size_type; typedef typename rep::difference_type difference_type; typedef typename rep::value_type value_type; typedef typename rep::reference reference; typedef typename rep::dis_reference dis_reference; typedef typename rep::iterator iterator; typedef typename rep::const_reference const_reference; typedef typename rep::const_iterator const_iterator; // allocators: array (size_type loc_size = 0, const T& init_val = T(), const A& alloc = A()); void resize (size_type loc_size = 0, const T& init_val = T()); array (const distributor& ownership, const T& init_val = T(), const A& alloc = A()); void resize (const distributor& ownership, const T& init_val = T()); // local accessors & modifiers: A get_allocator() const { return base::data().get_allocator(); } size_type size () const { return base::data().size(); } size_type dis_size () const { return base::data().dis_size(); } const distributor& ownership() const { return base::data().ownership(); } const communicator& comm() const { return ownership().comm(); } reference operator[] (size_type i) { return base::data().operator[] (i); } const_reference operator[] (size_type i) const { return base::data().operator[] (i); } reference operator() (size_type i) { return base::data().operator[] (i); } const_reference operator() (size_type i) const { return base::data().operator[] (i); } const_reference dis_at (size_type dis_i) const { return operator[] (dis_i); } iterator begin() { return base::data().begin(); } const_iterator begin() const { return base::data().begin(); } iterator end() { return base::data().end(); } const_iterator end() const { return base::data().end(); } // global modifiers (for compatibility with distributed interface): dis_reference dis_entry (size_type dis_i) { return base::data().dis_entry(dis_i); } void dis_entry_assembly() {} template<class SetOp> void dis_entry_assembly(SetOp my_set_op) {} template<class SetOp> void dis_entry_assembly_begin (SetOp my_set_op) {} template<class SetOp> void dis_entry_assembly_end (SetOp my_set_op) {} void reset_dis_indexes() const {} template<class Set> void set_dis_indexes (const Set& ext_idx_set) const {} template<class Set> void append_dis_indexes (const Set& ext_idx_set) const {} template<class Set, class Map> void append_dis_entry (const Set& ext_idx_set, Map& ext_idx_map) const {} template<class Set, class Map> void get_dis_entry (const Set& ext_idx_set, Map& ext_idx_map) const {} // apply a partition: template<class RepSize> void repartition ( // old_numbering for *this const RepSize& partition, // old_ownership array<T,sequential,A>& new_array, // new_ownership (created) RepSize& old_numbering, // new_ownership RepSize& new_numbering) const // old_ownership { return base::data().repartition (partition, new_array, old_numbering, new_numbering); } template<class RepSize> void permutation_apply ( // old_numbering for *this const RepSize& new_numbering, // old_ownership array<T,sequential,A>& new_array) const // new_ownership (already allocated) { return base::data().permutation_apply (new_numbering, new_array); } void reverse_permutation ( // old_ownership for *this=iold2dis_inew array<size_type,sequential,A>& inew2dis_iold) const // new_ownership { base::data().reverse_permutation (inew2dis_iold.data()); } // i/o: odiststream& put_values (odiststream& ops) const { return base::data().put_values(ops); } idiststream& get_values (idiststream& ips) { return base::data().get_values(ips); } template <class GetFunction> idiststream& get_values (idiststream& ips, GetFunction get_element) { return base::data().get_values(ips, get_element); } template <class PutFunction> odiststream& put_values (odiststream& ops, PutFunction put_element) const { return base::data().put_values(ops, put_element); } void dump (std::string name) const { return base::data().dump(name); } }; IMPLEMENTATION
template <class T, class A> class array<T,distributed,A> : public smart_pointer<array_mpi_rep<T,A> > { public: // typedefs: typedef array_mpi_rep<T,A> rep; typedef smart_pointer<rep> base; typedef distributed memory_type; typedef typename rep::size_type size_type; typedef typename rep::difference_type difference_type; typedef typename rep::value_type value_type; typedef typename rep::reference reference; typedef typename rep::dis_reference dis_reference; typedef typename rep::iterator iterator; typedef typename rep::const_reference const_reference; typedef typename rep::const_iterator const_iterator; typedef typename rep::scatter_map_type scatter_map_type; // allocators: array (const distributor& ownership = distributor(), const T& init_val = T(), const A& alloc = A()); void resize (const distributor& ownership = distributor(), const T& init_val = T()); // local accessors & modifiers: A get_allocator() const { return base::data().get_allocator(); } size_type size () const { return base::data().size(); } size_type dis_size () const { return base::data().dis_size(); } const distributor& ownership() const { return base::data().ownership(); } const communicator& comm() const { return base::data().comm(); } reference operator[] (size_type i) { return base::data().operator[] (i); } const_reference operator[] (size_type i) const { return base::data().operator[] (i); } reference operator() (size_type i) { return base::data().operator[] (i); } const_reference operator() (size_type i) const { return base::data().operator[] (i); } iterator begin() { return base::data().begin(); } const_iterator begin() const { return base::data().begin(); } iterator end() { return base::data().end(); } const_iterator end() const { return base::data().end(); } // global accessor: template<class Set, class Map> void append_dis_entry (const Set& ext_idx_set, Map& ext_idx_map) const { base::data().append_dis_entry (ext_idx_set, ext_idx_map); } template<class Set, class Map> void get_dis_entry (const Set& ext_idx_set, Map& ext_idx_map) const { base::data().get_dis_entry (ext_idx_set, ext_idx_map); } template<class Set> void append_dis_indexes (const Set& ext_idx_set) const { base::data().append_dis_indexes (ext_idx_set); } void reset_dis_indexes() const { base::data().reset_dis_indexes(); } template<class Set> void set_dis_indexes (const Set& ext_idx_set) const { base::data().set_dis_indexes (ext_idx_set); } const T& dis_at (size_type dis_i) const { return base::data().dis_at (dis_i); } // get all external pairs (dis_i, values): const scatter_map_type& get_dis_map_entries() const { return base::data().get_dis_map_entries(); } // global modifiers (for compatibility with distributed interface): dis_reference dis_entry (size_type dis_i) { return base::data().dis_entry(dis_i); } void dis_entry_assembly() { return base::data().dis_entry_assembly(); } template<class SetOp> void dis_entry_assembly (SetOp my_set_op) { return base::data().dis_entry_assembly (my_set_op); } template<class SetOp> void dis_entry_assembly_begin (SetOp my_set_op) { return base::data().dis_entry_assembly_begin (my_set_op); } template<class SetOp> void dis_entry_assembly_end (SetOp my_set_op) { return base::data().dis_entry_assembly_end (my_set_op); } // apply a partition: template<class RepSize> void repartition ( // old_numbering for *this const RepSize& partition, // old_ownership array<T,distributed>& new_array, // new_ownership (created) RepSize& old_numbering, // new_ownership RepSize& new_numbering) const // old_ownership { return base::data().repartition (partition.data(), new_array.data(), old_numbering.data(), new_numbering.data()); } template<class RepSize> void permutation_apply ( // old_numbering for *this const RepSize& new_numbering, // old_ownership array<T,distributed,A>& new_array) const // new_ownership (already allocated) { base::data().permutation_apply (new_numbering.data(), new_array.data()); } void reverse_permutation ( // old_ownership for *this=iold2dis_inew array<size_type,distributed,A>& inew2dis_iold) const // new_ownership { base::data().reverse_permutation (inew2dis_iold.data()); } // i/o: odiststream& put_values (odiststream& ops) const { return base::data().put_values(ops); } idiststream& get_values (idiststream& ips) { return base::data().get_values(ips); } void dump (std::string name) const { return base::data().dump(name); } template <class GetFunction> idiststream& get_values (idiststream& ips, GetFunction get_element) { return base::data().get_values(ips, get_element); } template <class PutFunction> odiststream& put_values (odiststream& ops, PutFunction put_element) const { return base::data().put_values(ops, put_element); } template <class PutFunction, class A2> odiststream& permuted_put_values ( odiststream& ops, const array<size_type,distributed,A2>& perm, PutFunction put_element) const { return base::data().permuted_put_values (ops, perm.data(), put_element); } }; SEE ALSO
distributor(2) rheolef-6.1 rheolef-6.1 array(2rheolef)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy