Original title:
Q: There are a.txt files, which are as follows 1234569 ABCABCABC requires awk to print the following results 987654321 CBACBACBA
A:
Shell: [Root@vps tmp]# rev A.txt 9654321 CBACBACBA
Perl: [Root@vps tmp]# perl-nle ' Print scalar reverse $_; ' A.txt 9654321 CBACBACBA
awk: [Root@vps tmp]# awk ' {num=split ($0,arr, ""); for (i=num;i>0;i–) {printf arr[i];if (i==1) {printf \ n '}}} ' A.txt 9654321 CBACBACBA
PHP: [Root@vps tmp]# php-r ' $fp =fopen ("A.txt", "R"); while (!feof ($fp)) {echo Strrev (fgets ($FP, 999));} echo "\ n";; ' 9654321 CBACBACBA
SED: [Root@vps tmp]# sed '/\n/! G;s/\ (. \) \ (. *\n\)/&\2\1/;//d;s/.//' a.txt 9654321 CBACBACBA
Python: (One of the methods)
>>> arr= ' Hello '
>>> Arr[::-1]
' Olleh '
(Method II)
>>> str= ' Hello '
>>> tmp= "
>>> for S in reversed (str):
... tmp+=s
...
>>> Print tmp
Olleh
Reverse.h
#ifndef _reverse_h
int getline (char s[],int limit);
void reverse (char s[]);
#endif
int getline (char s[],int limit)
{
int c,i;
for (i =0; ireverse.c
#include "stdio.h"
#include "/users/chenqing/tmp/reverse.h"
#define Maxline 1000
/*
Reverse a string use C Langusge
*/
int main (void)
{
int Len;
Char Line[maxline];
if (len = getline (line,maxline)) > 0) {
Reverse (line);
printf ("%s", line);
}
return 0;
}
GCC Reverse.c-o Reverse
Qing:tmp chenqing$ echo "ChinaCache" |. /reverse
EHCACANIHC above is the use of these implementations we are in the terminal command line to achieve a string flip example, haha, in fact, or Perl to achieve a better ah.