linux中用命令把"hello,world"倒序输出
2个回答
展开全部
不知道用的什么发行版,如果有rev命令这样操作比较简单:# echo "hello,world" | rev;
如果没有rev命令,大都会有sed命令:# echo "Hello,world" | sed -r '/\n/!G;s/(.)(.*\n)/&\2\1/;//D;s/.//';
如果没有rev命令,大都会有sed命令:# echo "Hello,world" | sed -r '/\n/!G;s/(.)(.*\n)/&\2\1/;//D;s/.//';
追问
非常感谢,其实我想知道的是 输出 world hello
追答
echo "hello world" | sed 's/(\w+) (\w+)/\2 \1/'
echo "hello world" | awk ' {print $2 " " $1}'
2019-04-12
展开全部
#include"stdio.h"
#include"unistd.h"
#include"stdlib.h"
#include"sys/stat.h"
#include"fcntl.h"
#define MAX_SIZE 1024
void sort1(){
int fd;
char buf;
long filelen=0;
int i,j=1;
int temp;
int stop[MAX_SIZE];
/*打开源文件*/
if((fd=open("data.txt", O_RDONLY|O_CREAT)) == -1){
printf("Open Error\n");
exit(1);
}
filelen=lseek(fd,0L,SEEK_END);
lseek(fd,0L,SEEK_SET);
stop[0]=-1;
while(i<filelen){
lseek(fd,i,SEEK_SET);
read(fd,&buf,1);
if(buf=='\n'){
stop[j]=i;
++j;
}
++i;
}
stop[j]=filelen+1;
while(j>0){
temp=stop[j-1]+1;
while(temp<(stop[j]+1))
{
lseek(fd,temp,SEEK_SET);
read(fd,&buf,1);
printf("%c",buf);
++temp;
}
--j;
}
}
void sort2(){
int fd;
char buff;
long filelen=0;
int i=1;
if((fd=open("data.txt", O_RDONLY|O_CREAT)) == -1){
printf("Open Error\n");
exit(1);
}
while(lseek(fd,i,SEEK_END)!=-1)
{
--i;
read(fd,&buff,1);
printf("%c",buff);
}
printf("\n");
}
int main(int argc,char **argv){
int ch;
opterr = 0;
while((ch = getopt(argc,argv,"a:bcde"))!= -1)
{
switch(ch)
{
case 'a': sort1();break;
case 'c': sort2(); break;
default: sort1();
}
}
}
#include"unistd.h"
#include"stdlib.h"
#include"sys/stat.h"
#include"fcntl.h"
#define MAX_SIZE 1024
void sort1(){
int fd;
char buf;
long filelen=0;
int i,j=1;
int temp;
int stop[MAX_SIZE];
/*打开源文件*/
if((fd=open("data.txt", O_RDONLY|O_CREAT)) == -1){
printf("Open Error\n");
exit(1);
}
filelen=lseek(fd,0L,SEEK_END);
lseek(fd,0L,SEEK_SET);
stop[0]=-1;
while(i<filelen){
lseek(fd,i,SEEK_SET);
read(fd,&buf,1);
if(buf=='\n'){
stop[j]=i;
++j;
}
++i;
}
stop[j]=filelen+1;
while(j>0){
temp=stop[j-1]+1;
while(temp<(stop[j]+1))
{
lseek(fd,temp,SEEK_SET);
read(fd,&buf,1);
printf("%c",buf);
++temp;
}
--j;
}
}
void sort2(){
int fd;
char buff;
long filelen=0;
int i=1;
if((fd=open("data.txt", O_RDONLY|O_CREAT)) == -1){
printf("Open Error\n");
exit(1);
}
while(lseek(fd,i,SEEK_END)!=-1)
{
--i;
read(fd,&buff,1);
printf("%c",buff);
}
printf("\n");
}
int main(int argc,char **argv){
int ch;
opterr = 0;
while((ch = getopt(argc,argv,"a:bcde"))!= -1)
{
switch(ch)
{
case 'a': sort1();break;
case 'c': sort2(); break;
default: sort1();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询