我试图将某些列从文件传递到awk脚本,并将1传递给它.输入文本文件"prac.txt"包含:
Shashank 12
Ram 13
Shyam 44
Run Code Online (Sandbox Code Playgroud)
awk脚本"awEg"包含:
#!/bin/awk -f
{
i=$2
print "val: ",$i+1;
}
Run Code Online (Sandbox Code Playgroud)
我要解雇的命令是:
more prac.txt |./awEg
Run Code Online (Sandbox Code Playgroud)
我得到低于输出:
val: 1
val: 1
val: 1
Run Code Online (Sandbox Code Playgroud)
请指出我的错误.
我在shell中有一个函数:
ConfigHandler(){
name=$1
dest=`awk -v file=$name -F"|" '{if($1~/file/)print $2}' ps.conf`
echo $dest
echo "Moving $1 to $dest ...."
mv `pwd`/$1 $dest/$1
echo ""
echo ""
}
Run Code Online (Sandbox Code Playgroud)
在调试模式下,我可以看到传递的值:
+ name=topbeat.yml
++ awk -v file=topbeat.yml '-F|' '{if($1~/file/)print $2}' ps.conf
+ dest=
Run Code Online (Sandbox Code Playgroud)
但我没有得到它的价值dest,我希望它是/etc/topbeat/,在哪里
awk -F"|" '{if($1~/topbeat/)print $2}' ps.conf
Run Code Online (Sandbox Code Playgroud)
返回预期的O/P即 /etc/topbeat/
ps.conf
topbeat.yml|/etc/topbeat/
logstash.conf|/opt/monitor/tools/etc/
jmxd.tar|/opt/
Run Code Online (Sandbox Code Playgroud) 如何订阅 Angular 服务中变量值的更改?
我已经做了很多搜索,但找不到解决方案(如果有可能的话!)。
我有一个component它是我的布局(标题)的一部分,它显示了购物车中的商品数量。该值绑定到变量simsInCartLength
然后我有一个service处理从购物车中添加和删除项目的操作。在serviceI 中有一个名为的变量noSims,用于存储购物车中项目数组的长度。
如何订阅对服务变量 noSims 的更改?
我的组件中的代码:
simsInCartLength = this.cartService.noSims;
Run Code Online (Sandbox Code Playgroud)
我的服务中的代码(当从购物车中添加或删除项目时,变量会更新:
this.noSims = this.simsInCart.length;
Run Code Online (Sandbox Code Playgroud)
先感谢您!
实际上我想使用*ngIf检查字符串是否以某个字符开头。
是否可以通过使用角度来做到这一点?我试过了,但出现错误
HTML
<app-breadcrumb *ngIf="startsWith:url === '/register/'"></app-breadcrumb>
Run Code Online (Sandbox Code Playgroud)
成分
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'startsWith'
})
export class UserComponent implements PipeTransform {
transform(fullText: string, textMatch: string): boolean {
return fullText.startsWith(textMatch);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在为我的 Angular 应用程序编写组件单元测试。currentUser我在组件和 html 模板中使用了一个变量。每次测试都会对其进行模拟(通过component.currentUser = {...}进行硬编码)。无论如何,业力失败了。将不胜感激任何帮助。
UserProfileComponent > should create
TypeError: Cannot read property 'id' of null
at UserProfileComponent.ngOnInit (http://localhost:9877/_karma_webpack_/webpack:/src/app/modules/user-profile/page/user-profile/user-profile.component.ts:4:21)
at callHook (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:2573:1)
at callHooks (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:2542:1)
at executeInitAndCheckHooks (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:2493:1)
at refreshView (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:9481:1)
at renderComponentOrTemplate (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:9580:1)
at tickRootContext (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:10811:1)
at detectChangesInRootView (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:10836:1)
at RootViewRef.detectChanges (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:22815:1)
at ComponentFixture._tick (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:141:1)
Run Code Online (Sandbox Code Playgroud)
下面的代码示例。
用户配置文件.component.ts
ngOnInit(): void {
this.currentUser = this.userService.getUser();
console.log(this.currentUser.id);
this.userAnnouncements();
}
Run Code Online (Sandbox Code Playgroud)
用户配置文件.组件.规格.ts
describe('UserProfileComponent', () => {
let component: UserProfileComponent;
let fixture: ComponentFixture<UserProfileComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({ …Run Code Online (Sandbox Code Playgroud) 我是Django Upgrade的新手,我尝试将版本从1.6.5升级到1.8.4.我手动安装1.8.4使用sudo python setup.py install.当我启动pycharm时,我得到以下错误.我检查__init__.py了检查错误,并试图找到1.8.4的示例文件以供参考.有人可以解释一下 - 如何逐步解决这些错误.
Failed to get real commands on module "albatross": python process died with code 1: Traceback (most recent call last):
File "/home/ritesh/Development/pycharm-4.5.3/helpers/pycharm/_jb_manage_tasks_provider.py", line 20, in <module>
django.setup()
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/conf/__init__.py", line 108, in __init__
"Please fix your settings." % setting)
django.core.exceptions.ImproperlyConfigured: The TEMPLATE_DIRS setting must be a …Run Code Online (Sandbox Code Playgroud) 我做了一个角度2的简单例子.我在数组中添加了项目.当用户键入任何内容并按下按钮时,它将被添加到数组中并显示在列表中.
我面临两个问题
2)角度2如何工作?如在文档Angular 2中删除监视.当项目添加到数组.how模板显示更新列表.how?
是在看列表模型吗?
这是我的plunker代码
<ion-navbar *navbar>
<ion-title>
Ionic 2
</ion-title>
</ion-navbar>
<ion-content class="has-header">
<ion-list style="border:2px solid grey;height:500px">
<ion-item *ngFor="#item of Todo">
{{item.name}}
</ion-item>
</ion-list>
<label class="item item-input">
<span class="input-label" >Add Todo</span>
<input type="text" #todo placeholder="Add todo" >
</label>
</ion-content>
<ion-footer-bar (click)="addItem(todo.value)">
<h1 class="title" style='color:red'>Add Todo!</h1>
</ion-footer-bar>
Run Code Online (Sandbox Code Playgroud) angular ×4
javascript ×3
typescript ×3
awk ×2
shell ×2
angularjs ×1
django ×1
html ×1
ionic2 ×1
pycharm ×1
python ×1
rxjs ×1
unit-testing ×1
unix ×1