Sponsored Content
Top Forums Shell Programming and Scripting Need help with switching field/column values Post 302166101 by KevinADC on Monday 11th of February 2008 01:36:38 AM
Old 02-11-2008
if all you really have is "a b" for each line:

perl -pi.bak -e 'chomp;$_=reverse($_)."\n"' yourfile.txt
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find top N values for field X based on field Y's value

I want to find the top N entries for a certain field based on the values of another field. For example if N=3, we want the 3 best values for each entry: Entry1 ||| 100 Entry1 ||| 95 Entry1 ||| 30 Entry1 ||| 80 Entry1 ||| 50 Entry2 ||| 40 Entry2 ||| 20 Entry2 ||| 10 Entry2 ||| 50... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

2. Shell Programming and Scripting

eAdd two fields in a column if their previous field values are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output file as follows If field3 in file1 is same as field3 in the next line then the field4 should add... (1 Reply)
Discussion started by: yerruhari
1 Replies

3. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

4. Shell Programming and Scripting

adding field values if field matches

hi i have file as below , i want to add duplicate records like bell_bb to one record with valuve as 15 ( addition of both ) any oneline awk script to achive this ? header 0 CAMPAIGN_NAME 1 Bell_BB 14 Bell_MONTHLY 803 SOLO_UNBEATABLE 644 Bell_BB 1 Bell_MONTHLY 25 SOLO_UNBEATABLE... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

5. Shell Programming and Scripting

counting lines containing two column field values with awk

Hello everybody, I'm trying to count the number of consecutive lines in a text file which have two distinctive column field values. These lines may appear in several line blocks within the file, but I only want a single block to be counted. This was my first approach to tackle the problem (I'm... (6 Replies)
Discussion started by: origamisven
6 Replies

6. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

7. UNIX for Dummies Questions & Answers

shift values in one column as header for values in another column

Hi Gurus, I have a tab separated text file with two columns. I would like to make the first column values as headings for the second column values. Ex. >value1 subjects >value2 priorities >value3 requirements ...etc and I want to have a file >value1 subjects >value2 priorities... (4 Replies)
Discussion started by: Unilearn
4 Replies

8. UNIX for Dummies Questions & Answers

Switching the values in a specific column of a text file

Hi, I have a space de-limited text file. In the fifth column, I would like to switch "1"s with "2"s. How do I go about doing that? Thanks! Sample input: 0 311000259 0 0 1 1 0 311000397 0 0 1 2 0 311000491 0 0 2 1 0 311000516 0 0 2 1 0 311000541 0 0 1 1 0 311000558 0 0 2 1 0 311000566 0... (1 Reply)
Discussion started by: evelibertine
1 Replies

9. Shell Programming and Scripting

Sum up the column values group by using some field

12-11-2012,PNL,158406 12-11-2012,RISK,4564 12-11-2012,VAR_1D,310101 12-11-2012,VAR_10D,310101 12-11-2012,CB,866 12-11-2012,STR_VAR_1D,298494 12-11-2012,STR_VAR_10D,309623 09-11-2012,PNL,1024106 09-11-2012,RISK,4565 09-11-2012,VAR_1D,317211 09-11-2012,VAR_10D,317211 09-11-2012,CB,985... (7 Replies)
Discussion started by: manas_ranjan
7 Replies

10. Shell Programming and Scripting

Sum column values matching other field

this is part of a KT i am going thru. i am writing a script in bash shell, linux where i have 2 columns where 1st signifies the nth hour like 00, 01, 02...23 and 2nd the file size. sample data attached. Desired output is 3 columns which will give the nth hour, number of entries in nth hour and... (3 Replies)
Discussion started by: alpha_1
3 Replies
Path::Class::File(3)					User Contributed Perl Documentation				      Path::Class::File(3)

NAME
Path::Class::File - Objects representing files VERSION
version 0.33 SYNOPSIS
use Path::Class; # Exports file() by default my $file = file('foo', 'bar.txt'); # Path::Class::File object my $file = Path::Class::File->new('foo', 'bar.txt'); # Same thing # Stringifies to 'foo/bar.txt' on Unix, 'fooar.txt' on Windows, etc. print "file: $file "; if ($file->is_absolute) { ... } if ($file->is_relative) { ... } my $v = $file->volume; # Could be 'C:' on Windows, empty string # on Unix, 'Macintosh HD:' on Mac OS $file->cleanup; # Perform logical cleanup of pathname $file->resolve; # Perform physical cleanup of pathname my $dir = $file->dir; # A Path::Class::Dir object my $abs = $file->absolute; # Transform to absolute path my $rel = $file->relative; # Transform to relative path DESCRIPTION
The "Path::Class::File" class contains functionality for manipulating file names in a cross-platform way. METHODS
$file = Path::Class::File->new( <dir1>, <dir2>, ..., <file> ) $file = file( <dir1>, <dir2>, ..., <file> ) Creates a new "Path::Class::File" object and returns it. The arguments specify the path to the file. Any volume may also be specified as the first argument, or as part of the first argument. You can use platform-neutral syntax: my $file = file( 'foo', 'bar', 'baz.txt' ); or platform-native syntax: my $file = file( 'foo/bar/baz.txt' ); or a mixture of the two: my $file = file( 'foo/bar', 'baz.txt' ); All three of the above examples create relative paths. To create an absolute path, either use the platform native syntax for doing so: my $file = file( '/var/tmp/foo.txt' ); or use an empty string as the first argument: my $file = file( '', 'var', 'tmp', 'foo.txt' ); If the second form seems awkward, that's somewhat intentional - paths like "/var/tmp" or "Windows" aren't cross-platform concepts in the first place, so they probably shouldn't appear in your code if you're trying to be cross-platform. The first form is perfectly fine, because paths like this may come from config files, user input, or whatever. $file->stringify This method is called internally when a "Path::Class::File" object is used in a string context, so the following are equivalent: $string = $file->stringify; $string = "$file"; $file->volume Returns the volume (e.g. "C:" on Windows, "Macintosh HD:" on Mac OS, etc.) of the object, if any. Otherwise, returns the empty string. $file->basename Returns the name of the file as a string, without the directory portion (if any). $file->components Returns a list of the directory components of this file, followed by the basename. Note: unlike "$dir->components", this method currently does not accept any arguments to select which elements of the list will be returned. It may do so in the future. Currently it throws an exception if such arguments are present. $file->is_dir Returns a boolean value indicating whether this object represents a directory. Not surprisingly, "Path::Class::File" objects always return false, and Path::Class::Dir objects always return true. $file->is_absolute Returns true or false depending on whether the file refers to an absolute path specifier (like "/usr/local/foo.txt" or "WindowsFoo.txt"). $file->is_relative Returns true or false depending on whether the file refers to a relative path specifier (like "lib/foo.txt" or ".Foo.txt"). $file->cleanup Performs a logical cleanup of the file path. For instance: my $file = file('/foo//baz/./foo.txt')->cleanup; # $file now represents '/foo/baz/foo.txt'; $dir->resolve Performs a physical cleanup of the file path. For instance: my $file = file('/foo/baz/../foo.txt')->resolve; # $file now represents '/foo/foo.txt', assuming no symlinks This actually consults the filesystem to verify the validity of the path. $dir = $file->dir Returns a "Path::Class::Dir" object representing the directory containing this file. $dir = $file->parent A synonym for the "dir()" method. $abs = $file->absolute Returns a "Path::Class::File" object representing $file as an absolute path. An optional argument, given as either a string or a Path::Class::Dir object, specifies the directory to use as the base of relativity - otherwise the current working directory will be used. $rel = $file->relative Returns a "Path::Class::File" object representing $file as a relative path. An optional argument, given as either a string or a "Path::Class::Dir" object, specifies the directory to use as the base of relativity - otherwise the current working directory will be used. $foreign = $file->as_foreign($type) Returns a "Path::Class::File" object representing $file as it would be specified on a system of type $type. Known types include "Unix", "Win32", "Mac", "VMS", and "OS2", i.e. anything for which there is a subclass of "File::Spec". Any generated objects (subdirectories, files, parents, etc.) will also retain this type. $foreign = Path::Class::File->new_foreign($type, @args) Returns a "Path::Class::File" object representing a file as it would be specified on a system of type $type. Known types include "Unix", "Win32", "Mac", "VMS", and "OS2", i.e. anything for which there is a subclass of "File::Spec". The arguments in @args are the same as they would be specified in "new()". $fh = $file->open($mode, $permissions) Passes the given arguments, including $file, to "IO::File->new" (which in turn calls "IO::File->open" and returns the result as an IO::File object. If the opening fails, "undef" is returned and $! is set. $fh = $file->openr() A shortcut for $fh = $file->open('r') or croak "Can't read $file: $!"; $fh = $file->openw() A shortcut for $fh = $file->open('w') or croak "Can't write to $file: $!"; $fh = $file->opena() A shortcut for $fh = $file->open('a') or croak "Can't append to $file: $!"; $file->touch Sets the modification and access time of the given file to right now, if the file exists. If it doesn't exist, "touch()" will make it exist, and - YES! - set its modification and access time to now. $file->slurp() In a scalar context, returns the contents of $file in a string. In a list context, returns the lines of $file (according to how $/ is set) as a list. If the file can't be read, this method will throw an exception. If you want "chomp()" run on each line of the file, pass a true value for the "chomp" or "chomped" parameters: my @lines = $file->slurp(chomp => 1); You may also use the "iomode" parameter to pass in an IO mode to use when opening the file, usually IO layers (though anything accepted by the MODE argument of "open()" is accepted here). Just make sure it's a reading mode. my @lines = $file->slurp(iomode => ':crlf'); my $lines = $file->slurp(iomode => '<:encoding(UTF-8)'); The default "iomode" is "r". Lines can also be automatically split, mimicking the perl command-line option "-a" by using the "split" parameter. If this parameter is used, each line will be returned as an array ref. my @lines = $file->slurp( chomp => 1, split => qr/s*,s*/ ); The "split" parameter can only be used in a list context. $file->spew( $content ); The opposite of "slurp", this takes a list of strings and prints them to the file in write mode. If the file can't be written to, this method will throw an exception. The content to be written can be either an array ref or a plain scalar. If the content is an array ref then each entry in the array will be written to the file. You may use the "iomode" parameter to pass in an IO mode to use when opening the file, just like "slurp" supports. $file->spew(iomode => '>:raw', $content); The default "iomode" is "w". $file->traverse(sub { ... }, @args) Calls the given callback on $file. This doesn't do much on its own, but see the associated documentation in Path::Class::Dir. $file->remove() This method will remove the file in a way that works well on all platforms, and returns a boolean value indicating whether or not the file was successfully removed. "remove()" is better than simply calling Perl's "unlink()" function, because on some platforms (notably VMS) you actually may need to call "unlink()" several times before all versions of the file are gone - the "remove()" method handles this process for you. $st = $file->stat() Invokes "File::stat::stat()" on this file and returns a File::stat object representing the result. $st = $file->lstat() Same as "stat()", but if $file is a symbolic link, "lstat()" stats the link instead of the file the link points to. $class = $file->dir_class() Returns the class which should be used to create directory objects. Generally overridden whenever this class is subclassed. $file->copy_to( $dest ); Copies the $file to $dest. $file->move_to( $dest ); Moves the $file to $dest. AUTHOR
Ken Williams, kwilliams@cpan.org SEE ALSO
Path::Class, Path::Class::Dir, File::Spec perl v5.18.2 2017-10-06 Path::Class::File(3)
All times are GMT -4. The time now is 08:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy