我有一个包含内容的文本文件:(version.txt)
<!-- my profile.html view -->
<ion-row>
<ion-col col-4>
Tipo de socio
</ion-col>
<ion-col col-8>
<span>{{ user.id }}</span><!-- cannot read id property of a null -->
</ion-col>
</ion-row>
<ion-row>
<ion-col col-4>
Tipo de socio
</ion-col>
<ion-col col-8>
<span>{{ user|json }}</span><!-- the data is returned -->
</ion-col>
</ion-row>
现在我有一个shell脚本,如下所示,它将version.txt的最后一行替换为 // My profile.ts ( where I'm loading the view and calling the user services )
import { User, UserService } from '../../app/models/user';
@Component({
selector: 'page-profile',
templateUrl: 'profile.html'
})
export class ProfilePage {
title = 'My Profile';
user: User = null;
private user_id: number = 0;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public alertCtrl: AlertController,
public modalCtrl: ModalController,
public loadingCtrl: LoadingController,
public userService: UserService) {
this.user_id = this.navParams.get('user_id'); // this value is working fine!
if ( this.user_id > 0 ) {
this.userService.get( this.user_id ).then( user => this.user = user );
}
}
ionViewDidLoad() { }
}
脚本:
// My user.ts ( where I've my services )
@Injectable()
export class User {
id: number;
name: string;
email: string;
ic: number;
birth_date: string;
home_phone: number;
phone: number;
is_active: boolean;
is_admin: boolean;
from_social_account: boolean;
is_superuser: boolean;
status: boolean;
created_at: any;
updated_at: any;
groups: any;
permissions: any;
addresses: any;
all_permissions: any;
auth_token: string;
is_customer: boolean;
is_partner: boolean;
last_login: string;
profile: any;
requests: any;
skills: any;
social_providers: any;
wallets: any;
errors: any = null;
birth_date_no_formatted: string;
main_address: any;
}
@Injectable()
export class UserService {
private headers: Headers = new Headers(Constant.DEFAULT_HEADERS);
private url: string = `${Constant.API_HOST}${Constant.API_PREFIX}${Constant.API_V1}`;
constructor(
private http: Http) { }
get( _id: number ): Promise<User> {
let url = `${this.url}users/${_id}/`;
return this.http.get(url, { headers: this.headers })
.toPromise().then( response => response.json() as User ).catch(this.handleError);
}
private handleError(error: any): any {
console.log( JSON.stringify( error ) );
return {errors: StaticMethods.formatSubmitErrors( error.json() ) };
}
}
但是它给出了这样的o / p:
<?php
if (isset($_GET['search']))
header("Location: https://www.siteb.com/#!q=".$_GET['search']."?parameter1");
?>
请告诉我这个剧本有什么问题?
提前致谢
答案 0 :(得分:1)
以下awk将帮助您增加Input_file中的版本。
awk -F'.' '/currentVersion/{$3=sprintf("%02d",$3+1)"}"} 1' OFS="." Input_file
输出如下。
{#Project Name: XYZ
#Module Name: ABC
#
#
currentVersion=9.2.05}
答案 1 :(得分:0)
基于this,我写道:
perl -pe 's/^currentVersion=((\d+\.)*)(\d+)(.*)$/$1.(sprintf("%02d", $3+1)).$4/e' file.txt