Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell script to reverse the contents of a file

Posted By: Luiz Silva     Category: Unix / Linux / Ubuntu     Views: 13182

Write a shell script to reverse the contents of a file.

Code for Write a shell script to reverse the contents of a file in Unix / Linux / Ubuntu

if [ $# -eq 1 ]
    then
        if [ -f $1 ]
            then
            a=`rev $1`
            echo "Reverse of $1"
                cat $1
            echo " is-> $a"else
            echo "File does not exist '
            fi      
    
    else
        echo "Please enter file name or path"
    fi

--------------------------------------------------------------------------------

OUTPUT:

    $ sh35  wordfile1
    Reverse of
    apple
    mango
    banana
    chicko
    is-> elppa
    ognam
    ananab
    okcihc   
$ sh10 sh9
-rwxrwxrwx  1 root     Everyone     262 Dec  7 18:48 sh9
$ sh10 /etc
total 813
-rwxrwxrwx  1 root     Everyone      46 Feb 15  1999 crontab
-rwxrwxrwx  1 root     Everyone     559 Dec  7 17:19 group
-rwxrwxrwx  1 root     Everyone   62464 Feb 15  1999 in.ftpd
-rwxrwxrwx  1 root     Everyone   35328 Feb  1  2000 in.rlogind
-rwxrwxrwx  1 root     Everyone   35328 Feb  3  2000 in.rshd
-rwxrwxrwx  1 root     Everyone   45056 Feb  1  2000 in.telnetd
-rwxrwxrwx  1 root     Everyone    4386 Jun  3  1999 inetd.conf
-rwxrwxrwx  1 root     Everyone   43520 Aug 25  2000 inetd.exe
-rwxrwxrwx  1 root     Everyone    1918 Jul  2  1999 inetdconfig.sh
-rwxrwxrwx  1 root     Everyone   21504 Feb 17  1999 init.exe
-rwxrwxrwx  1 root     Everyone       2 Jan  5  1999 login.allow
-rwxrwxrwx  1 root     Everyone       0 Dec  5  1998 login.deny
-rwxrwxrwx  1 root     Everyone     149 Mar  2  1999 mailx.rc
-rwxrwxrwx  1 root     Everyone   19968 Feb 17  1999 mkpasswd.exe
-rwxrwxrwx  1 root     Everyone     805 Dec  7 17:19 passwd
-rwxrwxrwx  1 root     Everyone     118 Feb  1  2000 passwd.add
-rwxrwxrwx  1 root     Everyone   25088 Feb 17  1999 priv.exe
-rwxrwxrwx  1 root     Everyone    1021 Jun 13  2000 profile
-rwxrwxrwx  1 root     Everyone     500 May 24  2000 rc
lrwxrwxrwx  1 root     Everyone      25 Dec  5 09:08 services -> /sys/drivers/etc/services
-rwxrwxrwx  1 root     Everyone      88 Feb 16  1999 shells
-rwxrwxrwx  1 root     Everyone     384 Dec  5 09:09 sidtable
-rwxrwxrwx  1 root     Everyone    1637 Jun  3  1999 stop_uwin
-rwxrwxrwx  1 root     Everyone       0 Dec  5 09:09 tryme
-rwxrwxrwx  1 root     Everyone   35840 Jun  7  2000 ucs.exe
-rwxrwxrwx  1 root     Everyone   76288 Jun 16  2000 ums.exe
$ sh10 /dev/null-rwxrwxrwx  1 root     Everyone       0 Dec  6 00:44 /dev/null
  
Share: 


Didn't find what you were looking for? Find more on Write a shell script to reverse the contents of a file Or get search suggestion and latest updates.

Luiz   Silva
Luiz Silva author of Write a shell script to reverse the contents of a file is from Salvador, Brazil.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Unix / Linux / Ubuntu:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!