awk

【Linux技术】ubuntu常用命令

自作多情 提交于 2020-01-22 07:26:47
查看软件xxx安装内容:dpkg -L xxx 查找软件库中的软件:apt-cache search 正则表达式 查找软件库中的软件:aptitude search 软件包 查找文件属于哪个包:dpkg -S filename 查找文件属于哪个包:apt-file search filename 查询软件xxx依赖哪些包:apt-cache depends xxx 查询软件xxx被哪些包依赖:apt-cache rdepends xxx 增加一个光盘源:sudo apt-cdrom add 系统升级:sudo apt-get update;sudo apt-get dist-upgrade 清除已删除包的残馀配置文件:dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P 编译时缺少h文件的自动处理:sudo auto-apt run ./configure 查看安装软件时下载包的临时存放目录:ls /var/cache/apt/archives 备份当前系统安装的所有包的列表:dpkg –get-selections | grep -v deinstall > ~/somefile 从备份的安装包的列表文件恢复所有包:dpkg –set-selections < ~/somefile;sudo dselect

get header of domains by bash script

℡╲_俬逩灬. 提交于 2020-01-22 02:55:14
问题 I write 10 domains in test.csv and trying to get the header of these 10 domains. but it won't read contents 1 by 1. and run this script for j in test.csv do awk -F',' '{ print "$1" }' $j | curl -Is | cat >> b.txt done I have about 10 million domains, and trying to get header by script. Any way possible ? 回答1: curl won't read URLs from stdin unless you tell it to do so. And you don't need a loop for this (assuming you have multiple files). What you're looking for is: awk -F',' '{ print "url="

Substituting shell variables into awk pattern looking scanning through file

…衆ロ難τιáo~ 提交于 2020-01-21 18:55:34
问题 NOTE : I am a noob at bash scripts and the awk command - please excuse any dumb mistakes I make. I am unable to substitute shell variables into my awk pattern. I am trying to scan through a file, find the first occurence of a specific string in the file, and print each line that succeed it in order until it hits an empty string/line. I don't know the string I am searching for in advance, and I would like to substitute in that variable. When I run this with the string directly specified (e.g "

awk的BEGIN和END

不羁岁月 提交于 2020-01-21 17:32:30
你可能对Unix比较熟悉,但你可能对Unix awk很陌生,这一点也不奇怪,的确,与其优秀的功能相比,awk还远没达到它应有的知名度。 流程控制语句是任何程序设计语言都不能缺少的部分。任何好的语言都有一些执行流程控制的语句。Unix awk提供的完备的流程控制语句类似于C语言,这给我们编程带来了极大的方便。 BEGIN和END: 在Unix awk中两个特别的表达式,BEGIN和END,这两者都可用于pattern中(参考前面的awk语法),提供BEGIN和END的作用是给程序赋予初始状态和在程序结束之后执行一些扫尾的工作。 任何在BEGIN之后列出的操作(在{}内)将在Unix awk开始扫描输入之前执行,而END之后列出的操作将在扫描完全部的输入之后执行。因此,通常使用BEGIN来显示变量和预置(初始化)变量,使用END来输出最终结果。 例:累计销售文件xs中的销售金额(假设销售金额在记录的第三字段): $``` awk 'BEGIN { FS=":";print "统计销售金额";total=0} {print $3;total=total+$3;} END {printf "销售金额总计:%.2f",total}' sx 例2:容量字段累加 grep '19/03/12 22:' nohup.out| grep Successfully|awk '{print $9}' |

Linux Command Line using for loop and formatting results

风流意气都作罢 提交于 2020-01-21 15:42:56
问题 How can I use one command line to provide a list of all files between a certain size and then format the file with name, md5 has and the file size. The example output should be file1.*** MD5 value size file2.*** MD5 value size etc. Ive tried the following but it displays the md5 on a separate line find 'directory' -size +30000c -size -50000c | while read filename do ls -l "$filename" | awk '{print $9 "\t" $5}' md5sum "$filename" | awk '{print $1}' done It outputs the follow with the MD5 on a

Linux Command Line using for loop and formatting results

走远了吗. 提交于 2020-01-21 15:41:33
问题 How can I use one command line to provide a list of all files between a certain size and then format the file with name, md5 has and the file size. The example output should be file1.*** MD5 value size file2.*** MD5 value size etc. Ive tried the following but it displays the md5 on a separate line find 'directory' -size +30000c -size -50000c | while read filename do ls -l "$filename" | awk '{print $9 "\t" $5}' md5sum "$filename" | awk '{print $1}' done It outputs the follow with the MD5 on a

grep command with a lookahead pattern does not select anything

大兔子大兔子 提交于 2020-01-21 14:39:47
问题 I was trying to use the following grep command: grep '(.*)(?=(png|html|jpg|js|css)(?:\s*))(png|html|jpg|js|css.*\s)' file File contains the following: http://manage.bostonglobe.com/GiftTheGlobe/LandingPage.html https://manage.bostonglobe.com/cs/mc/login.aspx?p1=BGFooter https://www.bostonglobe.com/bgcs /newsletters?p1=BGFooter_Newsletters https://bostonglobe.custhelp.com/app/home?p1=BGFooter https://bostonglobe.custhelp.com/app/answers/list?p1=BGFooter /tools/help/stafflist?p1=BGFooter https:

grep command with a lookahead pattern does not select anything

只愿长相守 提交于 2020-01-21 14:39:07
问题 I was trying to use the following grep command: grep '(.*)(?=(png|html|jpg|js|css)(?:\s*))(png|html|jpg|js|css.*\s)' file File contains the following: http://manage.bostonglobe.com/GiftTheGlobe/LandingPage.html https://manage.bostonglobe.com/cs/mc/login.aspx?p1=BGFooter https://www.bostonglobe.com/bgcs /newsletters?p1=BGFooter_Newsletters https://bostonglobe.custhelp.com/app/home?p1=BGFooter https://bostonglobe.custhelp.com/app/answers/list?p1=BGFooter /tools/help/stafflist?p1=BGFooter https:

How to change specific value of XML attribute using scripting on Mac

♀尐吖头ヾ 提交于 2020-01-21 12:25:20
问题 I have been tasked to write a script to change a specific value in an XML file on about 1000 Macs. Clearly this needs to be scripted, and preferably only using tools that are already available on a Mac (i.e. no additional installs needed). The end goal here is to disable IPv6 in a specific file related to active directory. For example: Old file: <IPv4> <script>Automatic</script> </IPv4> <IPv6> <script>Automatic</script> </IPv6> New file: <IPv4> <script>Automatic</script> </IPv4> <IPv6>

Memory efficient transpose - Awk

偶尔善良 提交于 2020-01-21 12:24:30
问题 i am trying to transpose a table (10k rows X 10K cols) using the following script. A simple data example $ cat rm1 t1 t2 t3 n1 1 2 3 n2 2 3 44 n3 1 1 1 $ sh transpose.sh rm1 n1 n2 n3 t1 1 2 1 t2 2 3 1 t3 3 44 1 However, I am getting memory error. Any help would be appreciated. awk -F "\t" '{ for (f = 1; f <= NF; f++) a[NR, f] = $f } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) for (r = 1; r <= NR; r++) printf a[r, f] (r==NR ? RS : FS) }' Error awk: cmd. line:2: (FILENAME=input FNR