Sponsored Content
Top Forums Shell Programming and Scripting Reversing text order of each line of a file in UNIX Post 302832669 by Skrynesaver on Monday 15th of July 2013 12:01:38 PM
Old 07-15-2013
Code:
perl -ne 'chomp;print join(" ",(reverse(split(/\s+/,$_)))),"\n";' filename

This User Gave Thanks to Skrynesaver For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

output string in reversing order

If I have string { I_love_shell_scripts} anyone knows how to have output {stpircs_llehs_evol_I} by using shell and perl ?I know in perl, there is reverse() funcation, but can it be done by not using reverse()? (3 Replies)
Discussion started by: ccp
3 Replies

2. Shell Programming and Scripting

Reversing file order using SED

Im trying to develop a shell script that will change the content order of the file. For example I have a file that says a b c d I want to change this to be d c b a Im trying to use sed to this by reading the file and then inserting each line at the top #!/usr/bin/ksh ... (3 Replies)
Discussion started by: MBGPS
3 Replies

3. Shell Programming and Scripting

reversing a line

Hi, I could not find this anywhere and I am wondering if someone knows a quick way of doing this. So heres the problem... I have a row that looks like this (an example): 5 4 3 2 1 What I want to do is reverse it so it looks like this: 1 2 3 4 5 Does anyone know the simple unix... (7 Replies)
Discussion started by: kylle345
7 Replies

4. Shell Programming and Scripting

reversing order of lines in a file

how can i reverse the line order in text files? (but total number of the lines is not constant ) for example i have a file like this: line1 line2 line3 . . lineN i wantto make it like this: lineN . . . line3 (26 Replies)
Discussion started by: gfhgfnhhn
26 Replies

5. Shell Programming and Scripting

Reversing a line based on column

Hi, I have a file that looks like this (tab seperated): read - DFHJ read1 - IOPE read2 + AAAB read3 + MMMN Basically what i want to do is reverse column 3 if column 2 has a - but leave it if its + so the output would look like this: read - JHFD read1 - EPOI read2 + AAAB... (3 Replies)
Discussion started by: kylle345
3 Replies

6. UNIX for Dummies Questions & Answers

Reversing line and word order using awk

Hello, I am new to awk and I was wandering if I could reverse line and word order from a text file using awk. I figured out how to do them both separately, but can't quite figure out how to mix them. Example: Input file: dog cat mouse 1 2 3 I am new to awk Output of the awk program:... (3 Replies)
Discussion started by: blink_w
3 Replies

7. UNIX for Dummies Questions & Answers

Appending a column of numbers in ascending order to a text file

I have a text file where I want to append a column of numbers in ascending orders. Input: 57 abc 25 def 32 ghi 54 jkl Output:57 abc 57 abc 1 25 def 2 32 ghi 3 54 jkl 4 How do I go about doing that? Thanks! (11 Replies)
Discussion started by: evelibertine
11 Replies

8. Windows & DOS: Issues & Discussions

Convert UNIX text file in Windows to recognize line breaks

Hmmm I think I found the correct subforum to ask my question... I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this?... (1 Reply)
Discussion started by: frys_hp
1 Replies

9. UNIX for Dummies Questions & Answers

Convert UNIX text file in Windows to recognize line breaks

Hi all, I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this? Or just reinsert thousands of line breaks again :eek: ? (2 Replies)
Discussion started by: frys_hp
2 Replies

10. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies
Test::Base::Filter(3pm) 				User Contributed Perl Documentation				   Test::Base::Filter(3pm)

NAME
Test::Base::Filter - Default Filter Class for Test::Base SYNOPSIS
package MyTestSuite; use Test::Base -Base; ... reusable testing code ... package MyTestSuite::Filter; use Test::Base::Filter -Base; sub my_filter1 { ... } DESCRIPTION
Filters are the key to writing effective data driven tests with Test::Base. Test::Base::Filter is a class containing a large default set of generic filters. You can easily subclass it to add/override functionality. FILTERS
This is a list of the default stock filters (in alphabetic order): append list => list Append a string to each element of a list. --- numbers lines chomp append=-# join one two three array list => scalar Turn a list of values into an anonymous array reference. base64_decode scalar => scalar Decode base64 data. Useful for binary tests. base64_encode scalar => scalar Encode base64 data. Useful for binary tests. chomp list => list Remove the final newline from each string value in a list. chop list => list Remove the final char from each string value in a list. dumper scalar => list Take a data structure (presumably from another filter like eval) and use Data::Dumper to dump it in a canonical fashion. escape scalar => scalar Unescape all backslash escaped chars. eval scalar => list Run Perl's "eval" command against the data and use the returned value as the data. eval_all scalar => list Run Perl's "eval" command against the data and return a list of 4 values: 1) The return value 2) The error in $@ 3) Captured STDOUT 4) Captured STDERR eval_stderr scalar => scalar Run Perl's "eval" command against the data and return the captured STDERR. eval_stdout scalar => scalar Run Perl's "eval" command against the data and return the captured STDOUT. exec_perl_stdout list => scalar Input Perl code is written to a temp file and run. STDOUT is captured and returned. flatten scalar => list Takes a hash or array ref and flattens it to a list. get_url scalar => scalar The text is chomped and considered to be a url. Then LWP::Simple::get is used to fetch the contents of the url. hash list => scalar Turn a list of key/value pairs into an anonymous hash reference. head[=number] list => list Takes a list and returns a number of the elements from the front of it. The default number is one. join list => scalar Join a list of strings into a scalar. Join Join the list of strings inside a list of array refs and return the strings in place of the array refs. lines scalar => list Break the data into an anonymous array of lines. Each line (except possibly the last one if the "chomp" filter came first) will have a newline at the end. norm scalar => scalar Normalize the data. Change non-Unix line endings to Unix line endings. prepend=string list => list Prepend a string onto each of a list of strings. read_file scalar => scalar Read the file named by the current content and return the file's content. regexp[=xism] scalar => scalar The "regexp" filter will turn your data section into a regular expression object. You can pass in extra flags after an equals sign. If the text contains more than one line and no flags are specified, then the 'xism' flags are assumed. reverse list => list Reverse the elements of a list. Reverse list => list Reverse the list of strings inside a list of array refs. slice=x[,y] list => list Returns the element number x through element number y of a list. sort list => list Sorts the elements of a list in character sort order. Sort list => list Sort the list of strings inside a list of array refs. split[=string|pattern] scalar => list Split a string in into a list. Takes a optional string or regexp as a parameter. Defaults to /s+/. Same as Perl "split". Split[=string|pattern] list => list Split each of a list of strings and turn them into array refs. strict scalar => scalar Prepend the string: use strict; use warnings; to the block's text. tail[=number] list => list Return a number of elements from the end of a list. The default number is one. trim list => list Remove extra blank lines from the beginning and end of the data. This allows you to visually separate your test data with blank lines. unchomp list => list Add a newline to each string value in a list. write_file[=filename] scalar => scalar Write the content of the section to the named file. Return the filename. yaml scalar => list Apply the YAML::Load function to the data block and use the resultant structure. Requires YAML.pm. AUTHOR
Ingy dA~Xt Net <ingy@cpan.org> COPYRIGHT
Copyright (c) 2006, 2011. Ingy dA~Xt Net. All rights reserved. Copyright (c) 2005. Brian Ingerson. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.12.3 2011-04-04 Test::Base::Filter(3pm)
All times are GMT -4. The time now is 05:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy