在unix上打印出整数文字 [英] Printing out integer literals occurences on unix

查看:168
本文介绍了在unix上打印出整数文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用grep命令打印出foo.txt文件中所有出现的整数字面值,但似乎无法找到方法。



我能想到的唯一想法就是使用[0-9]作为我的模式,但是它会打印所有出现数字的行而不仅仅是文字。



编辑:说foo.txt包含:

  string string1 =Hello world; 
cout <<<<< lt1;<< lt1;< ltl< lt;<

$ b然后,预期的输出将是:

  cout<< string1.at(2)<< endl; 
cout<< string1at(3)<< endl;
< / code>< / pre>

解决方案

有些人喜欢这样:

  awk  - F[()]'$ 2'foo.txt 
cout<< string1.at(2)<< endl;;
cout<<< string1at(3)<< ; endl;

或者确定它包含ns数字:

  awk -F[()]'$ 2〜/ [0-9] + /'文件
cout<< string1.at(2)<< ENDL;
cout<< string1at(3)<< ENDL;


I"m trying to use the grep command to print out all occurrences of integer literals in a foo.txt file, but I can't seem to find a way how.

The only think I can think of for this is using [0-9] as my pattern, but that prints all lines with occurrences of the number rather than just the literals.

EDIT: Say foo.txt contains:

string string1 = "Hello world";
cout << string1.at(2) << endl;
cout << string1at(3) << endl;

Then the expected output would be:

cout << string1.at(2) << endl;
cout << string1at(3) << endl;

解决方案

Some like this:

awk -F"[()]" '$2' foo.txt
cout << string1.at(2) << endl;
cout << string1at(3) << endl;

Or to make sure it contains numbers between parentheses:

awk -F"[()]" '$2~/[0-9]+/' file
cout << string1.at(2) << endl;
cout << string1at(3) << endl;

这篇关于在unix上打印出整数文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆