我在文本文件中有以下输出:
106 pages in list
.bookmarks
20130516 - Daily Meeting Minutes
20130517 - Daily Meeting Minutes
20130520 - Daily Meeting Minutes
20130521 - Daily Meeting Minutes
Run Code Online (Sandbox Code Playgroud)
我想从输出中删除前两行.我用来执行的这个特殊shell脚本总是有前两行.
这是我生成和读取文件的方式:
#Lists
PGLIST="$STAGE/pglist.lst";
RUNSCRIPT="$STAGE/runPagesToMove.sh";
#Get List of pages
$ATL_BASE/confluence.sh $CMD_PGLIST $CMD_SPACE "$1" > "$PGLIST";
# BUILD executeable script
echo "#!/bin/bash" >> $RUNSCRIPT 2>&1
IFS=''
while read line
do
echo "$ATL_BASE/conflunce.sh $CMD_MVPAGE $CMD_SPACE "$1" --title \"$line\" --newSpace \"$2\" --parent \"$3\"" >> $RUNSCRIPT 2>&1
done < $PGLIST
Run Code Online (Sandbox Code Playgroud)
如何删除前两行?
我正在使用redshift,并希望创建一个以逗号分隔的列列表.我正在尝试使用listagg以下方法从信息模式中获取列名:
SELECT
listagg(column_name,',') within group (order by ordinal_position)
FROM information_schema.columns
WHERE table_schema = 'my_schema'
AND table_name = 'my table';
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
[Amazon](500310) Invalid operation: Function (listagg(text,text)) must be applied on at least one user created tables;
Run Code Online (Sandbox Code Playgroud) 为什么我无法用这个#评论完成我的bash脚本?我的脚本没有执行通过注释行.是否与\前一行中使用反冲有关?
"$PSQL_HOME"/psql -h $HOST_NM \
-p $PORT \
-U postgres \
-v v1=$1 \
-v v2=$_load \
# -f Test.sql
-f Test2.sql
Run Code Online (Sandbox Code Playgroud) 需要帮助修复此bash脚本以设置包含双引号值的变量.不知何故,我将此错误地定义为我的值,foo并且bar根据需要不用双引号括起来.
到目前为止我的脚本:
#!/usr/local/bin/bash
set -e
set -x
host='127.0.0.1'
db='mydev'
_account="foo"
_profile="bar"
_version=$1
_mongo=$(which mongo);
exp="db.profile_versions_20170420.find({account:${_account}, profile:${_profile}, version:${_version}}).pretty();";
${_mongo} ${host}/${db} --eval "$exp"
set +x
Run Code Online (Sandbox Code Playgroud)
输出显示:
+ host=127.0.0.1
+ db=mydev
+ _account=foo
+ _profile=bar
+ _version=201704112004
++ which mongo
+ _mongo=/usr/local/bin/mongo
+ exp='db.profile_versions_20170420.find({account:foo, profile:bar, version:201704112004}).pretty();'
+ /usr/local/bin/mongo 127.0.0.1/mydev --eval 'db.profile_versions_20170420.find({account:foo, profile:bar, version:201704112004}).pretty();'
MongoDB shell version: 3.2.4
connecting to: 127.0.0.1/mydev
2017-04-22T15:32:55.012-0700 E QUERY [thread1] ReferenceError: foo is not defined :
@(shell eval):1:36
Run Code Online (Sandbox Code Playgroud)
我需要的是account:"foo",profile:"bar"用双引号括起来.
我使用sed来取代我的新行文件\n与','然而,工作正常,在我的最后一个项目,我不想要的,.
我该如何删除?
例:
sed 's/\n/,/g' myfile.out > myfile.csv
Run Code Online (Sandbox Code Playgroud)
输出:
1,2,3,4,5,6,
Run Code Online (Sandbox Code Playgroud) 我需要使用正则表达式的帮助.我有一些关于这些可能性用例的字符串.该字符串将始终以大写字母开头,后跟3个数字,然后是连字符,后跟数字:
A012-123
B001-012
C023-456
Run Code Online (Sandbox Code Playgroud)
我试过了:[A-Z0-9]-[0-9]我无法得到一个匹配.有人能告诉我如何正确构建这个吗?
Python新手在这里.我一直在努力通过这段代码基本上创建一个包含日期的字符串.我有一些代码工作来获取我想要的数据,但是我需要帮助格式化字符串以将数据绑定在一起.
这是我到目前为止:
def get_rectype_count(filename, rectype):
return int(subprocess.check_output('''zcat %s | '''
'''awk 'BEGIN {FS=";"};{print $6}' | '''
'''grep -i %r | wc -l''' %
(filename, rectype), shell=True))
str = "MY VALUES ("
rectypes = 'click', 'bounce'
for myfilename in glob.iglob('*.gz'):
#print (rectypes)
print str.join(rectypes)
print (timestr)
print([get_rectype_count(myfilename, rectype)
for rectype in rectypes])
Run Code Online (Sandbox Code Playgroud)
我的输出如下:
clickMY VALUES (bounce
'2015-07-01'
[222, 0]
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建此输出文件:
MY VALUES ('2015-07-01', click, 222)
MY VALUES ('2015-07-01', bounce, 0)
Run Code Online (Sandbox Code Playgroud)